0
votes

I have a windows 8.1 app.

In Project.Shared there is ResourceDictionary SharedResources.xaml with base style,

<Style x:Key="CommonLayerListItemStyle" TargetType="TextBlock">
    <Setter Property="FontFamily" Value="Segoe WP" />
    <Setter Property="Foreground" Value="{StaticResource UnselectBrush}" />
    <Setter Property="VerticalAlignment" Value="Stretch" />
</Style>

in Windows Phone app is StyleResources.xaml wiht style based on this

<Style x:Key="LayerListItemStyle"   
       BasedOn="{StaticResource CommonLayerListItemStyle}"
       TargetType="TextBlock">
    <Setter Property="FontSize" Value="20" />        
</Style>

same in Windows app StyleResources.xaml:

<Style x:Key="LayerListItemStyle"
       BasedOn="{StaticResource CommonLayerListItemStyle}"
       TargetType="TextBlock">
    <Setter Property="FontSize" Value="28" />
    <Setter Property="Margin" Value="42,0,0,0" />
</Style>

All styles are used in UserControl created in Shared project. I do this to override FontSize on diffrent platforms.

I merged all dictionaries in App.xaml

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="Styles/SharedResources.xaml" />
    <ResourceDictionary Source="Styles/StyleResources.xaml" />
</ResourceDictionary.MergedDictionaries>

But my app does not start with Unhandled exception Cannot find a Resource with the Name/Key CommonLayerListItemStyle [Line: 10 Position: 37]

Why does this happens?

1
Please see the comment below the accepted answer of [this][1] question. [1]: stackoverflow.com/questions/1652420/…KenIchi

1 Answers

0
votes

I had the same issue. You need to merge the SharedResources.xaml directly into StyleResources.xaml, and only reference StyleResources.xaml from App.xaml.

Here is a complete example: http://blog.craftingbytes.com/2015/05/resource-sharing-in-windows-universal.html