Page 1 of 1

[Unity] Style-Inheritance

Posted: 07 Sep 2014, 20:02
by Scherub

a few days ago I stumbled over another problem. This time with style inheritance from resource dictionaries that doesn't seem to work. First I thought the problem was that Noesis doesn't support deriving from a default (target-type/ key-less) style. So I gave the style a certain key but that still didn't solve the problem as it was saying:
Parsing StaticResource (@117,3).
Resource 'DefaultButtonStyle' not found
Eventually I figured that the problem occured only in the following scenario:

1. Define the default style in a shared resource dictionary.
2. Define the explicit style in the xaml (UserControl) where you're going to use the style.
<Style x:Key="DefaultButtonStyle" TargetType="Button">

<Style x:Key="ToolButtonStyle" TargetType="Button" BasedOn="{StaticResource DefaultButtonStyle}">

So above does work when both styles are defined in either the resource dictionary or in the UserControl-xaml. But it doesn't work if one style is defined in the resource dictionary and the other one is defined in the UserControl-xaml.

Re: [Unity] Style-Inheritance

Posted: 10 Sep 2014, 10:51
by sfernandez

This is a limitation of our current XAML asset build process.

The Style.BasedOn property accepts only a Style object, so when a XAML is built by our system (creating a binary representation for runtime), it tries to solve the StaticResource assigned to that property (DynamicResource can't be used in WPF neither) before setting the value. The problem here is that XAML dependencies (merged dictionaries) are not available during build process, so we cannot find resources that are defined in other xamls.

The limitation does not apply when using StaticResource/DynamicResource over a DependencyProperty because in that case we can store the generated Expression and solve it on runtime (when XAML dependencies are already loaded).

Please file a bug in our bugtracker. We will find a solution to fix it in a future release.