Avoid XAML Code Duplication
I am very new to WPF. The UI I was required to implement makes use of buttons that contain both an image and a textual label. Creating one of these buttons is straightforward: I set the button's content to a UniformGrid and drop an image and a label into the grid. However, since there are quite a few of these buttons in my GUI, how do I avoid copy-pasting the XAML that defines this button multiple times, and instead "refactor" it into something I can just code once and easily maintain later? Is a Custom Control considered overkil开发者_JAVA技巧l for this issue? Is there a simpler, built-in solution I'm missing?
You can use Control Templates to specify the visual tree of your buttons... Do a google search, there's heaps of good documentation and examples around...
Also, TemplateBinding will allow you to pass properties from a control into the Template...
Ian
精彩评论