Reputation: 8003
I'm new to WPF and I have a question:
In my projects I usually use many usercontrols, that are derived from my 'base' usercontrol, that have some functions to inherit to all my usercontrols.
With WPF (the derivation is the same that the winforms) is it possible derive also the XAML? I wish to create one XAML with the header with the XML namespace, and important UserControl.Resources.
Is it possible?
Thanks in advance
Upvotes: 1
Views: 851
Reputation: 501
If you're looking to share Resources across your user controls, put them in a Style targeting your user control base type. To have these resources accessible (and applied) across the entire application, defined them in the App.xaml.
You can either define them in the Style of your base type:
<Style TargetType={x:Type YourBaseType}>
<Style.Resources>
<!-- define your resources here -->
</Style.Resources>
</Style>
Or, you could apply them to all UserControls (probably non advisable):
<Style TargetType={x:Type UserControl}>
<Style.Resources>
<!-- define your resources here -->
</Style.Resources>
</Style>
If you're looking to derive visual aspects, again use the Style, applying Setters in the App.config definition. These can then be "overidden" by the specific instance if required. Also have a look at the ControlTemplate.
Upvotes: 2