Create style BasedOn StandardStyles.xaml in Metro App

Go To


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.

2012-04-04 01:08
by Clever Human


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 Source="Common/StandardStyles.xaml" />

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.

2012-04-04 01:16
by xanadont
You are brilliant and wise in the ways of the Xaml. I bow before your magnificence - Clever Human 2012-04-06 03:15
Ha, hardly! It's just an extremely steep learning curve, but the climb is virtuous. Stick with it. The model binding alone is sublime. You'll learn to love it - xanadont 2012-04-07 21:42