This is a migrated thread and some comments may be shown as answers.

ResourceDictionary Source File VS local Style

4 Answers 636 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Gert
Top achievements
Rank 1
Gert asked on 24 Feb 2020, 01:47 PM

Hi,

why is this working:

<telerik:RadRibbonWindow
    x:Class="N4W.App.GuiLayer.Modules.OperatingCostsModule.Views.ProceedTest"
    xmlns:local="clr-namespace:N4W.App.GuiLayer.Modules.OperatingCostsModule.Views"
    mc:Ignorable="d" Height="200" Width="400"
    d:DesignHeight="450" d:DesignWidth="800">
 
    <telerik:RadRibbonWindow.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <!--<ResourceDictionary>
                    <Style TargetType="local:ProceedTest" BasedOn="{StaticResource RadRibbonWindowStyle}" />
                </ResourceDictionary>-->                                          
 
                <ResourceDictionary Source="RibbonWindowStyle.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </telerik:RadRibbonWindow.Resources>
    <Grid>
        <TextBlock Text="Hallo" />
    </Grid>
</telerik:RadRibbonWindow>

where the content of RibbonWindowStyle.xaml is:

                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:N4W.App.GuiLayer.Modules.OperatingCostsModule.Views"
                    >
     
    <Style TargetType="local:ProceedTest" BasedOn="{StaticResource RadRibbonWindowStyle}" />
 
</ResourceDictionary>

pic RadWindow2.jpg

 

and this is not working:

<telerik:RadRibbonWindow
    x:Class="N4W.App.GuiLayer.Modules.OperatingCostsModule.Views.ProceedTest"
    xmlns:local="clr-namespace:N4W.App.GuiLayer.Modules.OperatingCostsModule.Views"
    mc:Ignorable="d" Height="200" Width="400"
    d:DesignHeight="450" d:DesignWidth="800">
 
    <telerik:RadRibbonWindow.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary>
                    <Style TargetType="local:ProceedTest" BasedOn="{StaticResource RadRibbonWindowStyle}" />
                </ResourceDictionary>                                          
 
                <!--<ResourceDictionary Source="RibbonWindowStyle.xaml" />-->
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </telerik:RadRibbonWindow.Resources>
    <Grid>
        <TextBlock Text="Hallo" />
    </Grid>
</telerik:RadRibbonWindow>

pic RadWindow1.jpg

 

For me both versions should end up in the same result, or what is the difference?!

 

BR Gert

 

 

 

 

 

4 Answers, 1 is accepted

Sort by
0
Sia
Telerik team
answered on 27 Feb 2020, 01:22 PM

Hello Gert,

Instead of merging the RibbonWindow style inside its resources:

<ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary>
            <Style TargetType="local:MainWindow" BasedOn="{StaticResource RadRibbonWindowStyle}" />
        </ResourceDictionary> 
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

 

merge it directly as follows:

<telerik:RadRibbonWindow.Resources>
    <Style TargetType="local:MainWindow" BasedOn="{StaticResource RadRibbonWindowStyle}" />
</telerik:RadRibbonWindow.Resources>

Please find a sample project attached.

Regards,
Sia
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Gert
Top achievements
Rank 1
answered on 28 Feb 2020, 10:48 AM

Hi Sia,

that was not my question!

I know (in the meantime) that there are many way to base on a style, but my initial question (out of curiosity) was why my two approaches did not the same thing...

 

 

BR Gert

0
Accepted
Sia
Telerik team
answered on 04 Mar 2020, 10:32 AM

Hello Gert,

My change was not related to the way you base your style but to the hierarchy of resource dictionaries in your application.

I believe that the reported issue is related to the way the framework works for optimizing the lookup through resource dictionaries.

A logged issue can be found on the Microsoft developer community portal and also in GitHub.

Please find a modified version of the same sample project attached to my answer, where the same issue is reproduced with a TextBlock (the style is not applied to the first one). Adding a dummy style works fine.

The approach with a dummy style can be used for the RibbonWindow Style as well:

<ResourceDictionary>
    <Style TargetType="{x:Type Ellipse}"/>
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary>
            <Style TargetType="local:MainWindow" BasedOn="{StaticResource RadRibbonWindowStyle}" />
        </ResourceDictionary>
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

However I would not recommend using a deep hierarchy of resource dictionaries in your application.

Microsoft defines setting a ResourceDictionary's content inline as not a common scenario and recommends defining such styles in the main ResourceDictionary and not in the merged dictionaries as was my first proposal.

More information about the latest can be found in the Microsoft article about Merged Resource Dictionaries and the Note quoted below:

It is legal to define resources within a ResourceDictionary that is specified as a merged dictionary, either as an alternative to specifying Source, or in addition to whatever resources are included from the specified source. However, this is not a common scenario; the main scenario for merged dictionaries is to merge resources from external file locations. If you want to specify resources within the markup for a page, you should typically define these in the main ResourceDictionary and not in the merged dictionaries.

I hope this helps.

Regards,
Sia
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Gert
Top achievements
Rank 1
answered on 04 Mar 2020, 10:36 AM

Hi Sia,

thanks for the good explanation. Now it is more clear for me.

BR Gert

Tags
General Discussions
Asked by
Gert
Top achievements
Rank 1
Answers by
Sia
Telerik team
Gert
Top achievements
Rank 1
Share this question
or