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}
精彩评论