ResourceDictionary Source File VS local Style

5 posts, 1 answers
  1. Gert
    Gert avatar
    35 posts
    Member since:
    Nov 2017

    Posted 24 Feb Link to this post

    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

     

     

     

     

     

  2. Sia
    Admin
    Sia avatar
    756 posts

    Posted 27 Feb Link to this post

    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.
  3. Gert
    Gert avatar
    35 posts
    Member since:
    Nov 2017

    Posted 28 Feb in reply to Sia Link to this post

    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

  4. Answer
    Sia
    Admin
    Sia avatar
    756 posts

    Posted 04 Mar Link to this post

    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.
  5. Gert
    Gert avatar
    35 posts
    Member since:
    Nov 2017

    Posted 04 Mar in reply to Sia Link to this post

    Hi Sia,

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

    BR Gert

Back to Top