I have two simple custom controls derived from standard WPF controls. I.e.
internal class CustomLabel : Label { ... }
internal class CustomButton : Button { ... }
(Ok, actually I use GridViewHeaderRowPresenter and DataGrid from WPF Toolkit, not Label and Button).
In xaml they locate on the same hierarchy level.
<Grid>
<CustomLabel />
<开发者_如何转开发;CustomButton />
</Grid>
The CustomButton control should react in some way to CustomLabel's event (say SizeChanged event). What is the best way to implement this?
So far I came to decision to traverse logical tree to find CustomButton in CustomLabel's event handler and change some properties. Is there better way?
Please note I am using .Net 3.5 so cannot use x:Reference markup extension.
You can give your controls names and access them using this name in your code behind. If you want to do it exclusively in XAML think about data binding and whether or not your goal can be achieved using this approach.
精彩评论