1

I am currently trying to create a ResourceDictionary. I have 2 projects (The main project with App.xaml & MainPage.xaml and another project which contains only subpages) and want to define a ResourceDictionary with different styles for specific elements in my subpages. E.g. I have a ListView with some TextBlocks and Images and want every TextBlock to have the same style. How do I achieve that? Is it correct to save the ResourceDictionary in the main project and implement it in the App.xaml? If so, how can my subproject use these Resources?

Some more information on how my project looks like:

MainProject

MyResourceDictionary.XAML

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:MainProject">

    <Style x:Key="ListViewTextBlock" TargetType="TextBlock">
        <Setter Property="FontSize" Value="24"/>
        <Setter Property="Foreground" Value="White"/>
    </Style>    
</ResourceDictionary>

App.xaml

<Application.Resources>
    <ResourceDictionary Source="ResourceDictionary/MyResourceDictionary.xaml"/>
</Application.Resources>

SubProject

MySubPage.xaml

<ListViewItem ...>
    <Grid...>
        <Grid.ColumnDefinitions.../>
            <TextBlock Grid.Column="0" Style={?} Text="Give me style!"/>
            <Image...>
    </Grid>
</ListViewItem>
Nigel-Lee
  • 145
  • 1
  • 13
  • What is your sub project for? – Justin XL Aug 23 '17 at 09:22
  • @JustinXL It contains Subpages which the MainProject navigates to (E.g. a Button on the MainPage.xaml navigates to another page via Frame.Navigate(typeof(FirstPage));) – Nigel-Lee Aug 23 '17 at 09:26
  • @nondestructive Yes, this solved my problem! But even though the Style is accepted by the element , the xaml designer hints me it cannot find my Resource? And should I add the line from the other post which solved my problem or is the reference to the other post enough? – Nigel-Lee Aug 23 '17 at 09:47
  • 1
    I'll take a look, but if a reference is marked as `Dynamic` (as opposed to `Static`), the designer sometimes (always?) marks it as not found. – nondestructive Aug 23 '17 at 09:49
  • If you want to know how to enable design-time resource in another project, open another question and I will answer it. – Justin XL Aug 23 '17 at 10:50

0 Answers0