开发者

wpf,How to find mainControl?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜