Why is the control inaccessible due to its protection level?

前端 未结 4 1340
时光说笑
时光说笑 2020-12-11 00:50

I\'m trying to access a control\'s text property from program.cs and it says that it is inaccessible due to protected level. How can I fix this please?

4条回答
  •  有刺的猬
    2020-12-11 01:12

    Use x:FieldModifier="public" e.g.

    
    

    as explained here: Modifying XAML named field visibility

    In my case, I put UserControl in another DLL. WPF’s convention is to set all named fields as internal by default. Using the x:FieldModifier="public" has solved the issue.

提交回复
热议问题