WPF. Get the value of the attached property from XAML, without object instantiation
I have some user control with attached property, e. g. Grid.Column. Usually, 开发者_JS百科to get the value of the attached property, I need an instance of dependency object.
Is there any way to get the value in code without instantiation of object?
In case of XAML like this:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
...
<TextBox x:Name="MyTextBox" Grid.Column="1" .../>
</Grid>
It is possible to get a value of the attached property like this:
var textBoxColumn = Grid.GetColumn(MyTextBox);
Grid.GetColumn
is a static method, so you don't need a reference to the object that defines this property, but you do need a reference to the object to which the property is attached.
精彩评论