开发者

wpf,How to find mainControl?

开发者 https://www.devze.com 2023-01-29 09:14 出处:网络
How to find UserControl Layer by grid? <UserControl ... ... &g开发者_开发百科t; <Grid name=\"grid\">

How to find UserControl Layer by grid?

<UserControl
 ... ...
 &g开发者_开发百科t;
  <Grid name="grid">
  </Grid>

I want to add resource to UserControl Layer in CodeBehind.

Grid contain lots of TextBox. it is invalid when i add resource to Grid.

ResourceDictionary resource = new ResourceDictionary();
            Style style = new Style(typeof(TextBox));
            style.Setters.Add(new Setter(TextBox.BorderThicknessProperty, new Thickness(0))); 


You can use the VisualTreeHelper to navigate and search in the visual tree.


If you want a reference to UserControl in code behind, you can use this keyword.

If you want to refer to it in a binding, use Ancestor binding like following :

{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}, Path=PropertyName}
0

精彩评论

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