开发者

WPF. Get the value of the attached property from XAML, without object instantiation

开发者 https://www.devze.com 2023-02-18 12:13 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消