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?
Control Protection level Resolved
Go to designer file search control By ID eg txtModel change protected modifier to public modifier
Use x:FieldModifier="public"
eg
<TextBlock x:FieldModifier="public" x:Name="AccessibleTextBlock" />
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.
The concept behind is the protection level. As we have studied in Object Oriented Paradigm keep your class members variables private and set or get it from Property.Thats why it is not a good approach
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.