How can I find WPF controls by name or type?

后端 未结 18 2944
庸人自扰
庸人自扰 2020-11-21 04:23

I need to search a WPF control hierarchy for controls that match a given name or type. How can I do this?

18条回答
  •  被撕碎了的回忆
    2020-11-21 04:46

    These options already talk about traversing the Visual Tree in C#. Its possible to traverse the visual tree in xaml as well using RelativeSource markup extension. msdn

    find by type

    Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type }}}" 
    

提交回复
热议问题