Assembly A - ResourceDictionary contains StyleA style.
Assembly B - ResourceDictionary.MergedDictionaries to merge resources from Assembly A into B.
I would like to create a style in Assembly B "based on" StyleA. Is it possible?
I am trying to create this style:
<Style x:Key="StyleB" BasedOn="{StaticResource StyleA}">
<Setter Property="Button.Foreground" Value="Khaki"/>
</Style>
But I get a XamlParseException exception at run-time, if I use StyleB:
Cannot convert the value in attribute 'Style' to object of type 'System.Windows.Style'. Can only base on a Style with target type that is base type 'IFrameworkInputElement'. Error at object 'System.Windows.Controls.Button' in markup file 'SamSeekApp;component/mainwindow.xaml'
WPF Styles consist of Setters and Triggers that are supposed to change the Style and Behavior of a Control. From a technical point of view the purpose of Styles is to set Dependency Properties on a Control. Some Use Cases of Styles: Change Colors of a Control
Create class in styles assembly which will extend abstract StyleRefExtension: You can use this class in any project and XAML designer will show you your styles. For example, I will create a WinForms project and will add WPF user control, and for example will use DynamicResource with referenced assembly: Yes, not working as expected...
The most common way to declare a style is as a resource in the Resources section in a XAML file. Because styles are resources, they obey the same scoping rules that apply to all resources. Put simply, where you declare a style affects where the style can be applied.
In this article I will introduce you into the concept of WPF Styles and Triggers. WPF Styles consist of Setters and Triggers that are supposed to change the Style and Behavior of a Control. From a technical point of view the purpose of Styles is to set Dependency Properties on a Control.
Try adding TargetType="{x:Type Button}" to your 'StyleB'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With