Is there any way to get XAML element by Tag property?

筅森魡賤 提交于 2019-12-02 21:46:25

问题


Is there any way to get the XAML element by its tag value??

My code is like this :

<Grid Tap="StackPanel_Tap" Tag="{Binding Type}" >
       <Border BorderThickness="0"  CornerRadius="0"  BorderBrush="White" Width="100" Height="100"  HorizontalAlignment="Center" VerticalAlignment="Center" Opacity="1" >
      <Image Tag="{Binding Type}" Source="{Binding Location}" Opacity="1" Width="100"  Height="100" Stretch="Fill" HorizontalAlignment="Center" VerticalAlignment="Center" UseLayoutRounding="True"  >
       </Image>
      </Border>
</Grid>

I am binding Tag Property for Grid , is there any way to get an object of Grid by using Tag Propertty??

Sorry for less information the thing is grid is in ListBox .. How can i Access The Grid Object??

Thanks and Reagrds Yashavantha


回答1:


Create a recursive method which uses System.Windows.Media.VisualTreeHelper to get all children of the page. For each child test if it's of type Grid and if it has a Tag equal to whatever you're looking for.



来源:https://stackoverflow.com/questions/12408473/is-there-any-way-to-get-xaml-element-by-tag-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!