Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create style BasedOn StandardStyles.xaml in Metro App

I am creating my first WPF metro app. I am trying to extend the styles that come as part of a Metro app (in the Common/StandardStyles.xaml files)

I am not modifying that file.

Instead, I've created another resource file (in the root) called AppStyles.xaml. In it I placed this style:

<!-- Apply to all textblocks-->
<Style BasedOn="{StaticResource BasicTextStyle}" TargetType="TextBlock">
    <Setter Property="Margin" Value="0,10,10,0"/></Style>

But when I run the application I get this error.

Cannot find a Resource with the Name/Key BasicTextStyle [Line: 17 Position: 44]

Is it not possible to do this?

(BTW, nowhere in the entire application does the BasicTextStyle get used or defined on Line 17 of any file, so I have no idea what page it is actually complaining about.)

The file that is handling the error, by the way is "App.g.i.cs" and it is the generic error handler.

The app runs fine if I remove the style I created.

like image 597
CleverPatrick Avatar asked Dec 28 '22 03:12

CleverPatrick


1 Answers

I don't know anything about Metro-specific apps, but this should be standard XAML stuff. You need something like this in your AppStyles.xaml file:

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="Common/StandardStyles.xaml" />
</ResourceDictionary.MergedDictionaries>

Once you have that may you refer to the resource in your custom XAML file. BTW, the error you're getting is referring to the AppStyles.xaml file itself.

like image 90
xanadont Avatar answered Feb 14 '23 02:02

xanadont