will do management public. To do this private, you must explicitl...">

Why is WPF not closed by default?

Write in WPF

<TextBlock x:Name="foo"/>

will do management public. To do this private, you must explicitly specify FieldModifier:

<TextBlock x:Name="foo" x:FieldModifier="private"/>

I find it strange. I don't think this is a good coding style for accessing subcontrol directly from outside the class. For example, I would avoid writing

var muc = new MyUserControl();
muc.foo.Text = "foo";

Instead, I would write a public method and use it:

public void SetFooText(string text) { foo.Text = text; }
// in somewhere else
var muc = new MyUserControl();
muc.SetFooText("foo");

or write a public property

public string FooText 
{ 
    get { return foo.Text; } 
    set { foo.Text = value; } 
}
// in somewhere else
var muc = new MyUserControl();
muc.FooText = "foo";

So, I really do not see any advantages when setting the controls publicto default. Maybe it would be safer if privateby default, like everything in C #.

Why publicby default?

Edit:

, . internal, . , private, .

+4
1

x: FieldModifier # - NotPublic (Internal)

TypeAttributes.NotPublic - , , , XAML, , XAML. WPF XAML , , x: FieldModifier, .

, , XAML XAML- .

MSDN

+7

Source: https://habr.com/ru/post/1674623/


All Articles