views:

43

answers:

1

I am attempting to create a Syles.xaml file for my test Silverlight app. Here is what I have in the App.xaml file:

<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
             xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
             xmlns:uriMapper="clr-namespace:System.Windows.Navigation;assembly=System.Windows.Controls.Navigation"
             x:Class="MVCSilverlight.App"
             >
    <Application.Resources>
        <Style x:Key="NavigationContainerStyle" TargetType="StackPanel">
            <Setter Property="Background" Value="Black" />
            <Setter Property="Orientation" Value="Horizontal" />
            <Setter Property="Height" Value="50" />
            <Setter Property="Width" Value="500" />
        </Style>
    </Application.Resources>
</Application>

The problem is that when I include this in the app, VS2010 does not recognize it AND when I run the application, it does not display because there are errors with attempting to find that resource name/value. Here is an example of how it is being used:

<StackPanel Style="{StaticResource NavigationContainerStyle}">
</StackPanel>

I also attempting to put the styles in a file and include it in the app.xaml but that didnt work either.

Can someone give me some ideas as to why this is happening?

+1  A: 

That XAML looks like it should work fine as long as App is still set as the startup object in the project settings and InitializeComponent() is still being called in App.xaml.cs.

If you are putting styles in a Styles.xaml file you will need use a merged resource dictionary to merge it into either the App resources or directly into the resources of the UserControl where you are going to use it.

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Styles.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>
Dan Auclair