Hi all,

I have a resource dictionary which is already added to the App.xaml however when I add the particular style to my Grid, it doesn't gets reflected while debugging.
Can anyone please help me on this ?
My codes are as follow :-

MainPage.xaml

<Grid x:Name="myGrid_MainPage" Style="{StaticResource myGridStyle}">

myRD_Main.xaml

<Style x:Key="myGridStyle" TargetType="Grid">
    <Setter Property="Grid.Background">
        <Setter.Value>
            <LinearGradientBrush>
                <GradientStopCollection>
                    <GradientStop Color="Red" Offset="0.5"></GradientStop>
                    <GradientStop Color="Black" Offset="0.5"></GradientStop>
                </GradientStopCollection>
            </LinearGradientBrush>
        </Setter.Value>
    </Setter>
</Style>

App.xaml

 <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="C:\Users\MyUser\documents\visual studio 2010\Projects\mySilverlight_App_Practice\mySilverlight_App_Practice\myResources\myRD_Main.xaml"></ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>

Recommended Answers

All 3 Replies

Member Avatar for LastMitch

I have a resource dictionary which is already added to the App.xaml however when I add the particular style to my Grid, it doesn't gets reflected while debugging.

Try to change the <Grid> tags.

From this

<Grid x:Name="myGrid_MainPage" Style="{StaticResource myGridStyle}">

to this:

<Grid x:Name="myGrid_MainPage" Background="White">
    <my:MainPage Background="blue"></my:MainPage>
</Grid>

When you run the code again does the <Grid> tags background is white?

If it's white then there's nothing wrong with your <Grid> tags then the issue is your

<Style x:Key="myGridStyle" TargetType="Grid">

Read this about <LinearGradientBrush>:

http://msdn.microsoft.com/en-us/library/ms635198.aspx

There's another thing I notice is this:

<ResourceDictionary Source="C:\Users\MyUser\documents\visual studio 2010\Projects\mySilverlight_App_Practice\mySilverlight_App_Practice\myResources\myRD_Main.xaml"></ResourceDictionary>

it should be just

<ResourceDictionary Source="myResources/myRD_Main.xaml"></ResourceDictionary>

Thanks a lot LastMitch, I changed the resource dictionary path as I think that it only takes the relative path but not the absolute one.
Now its working fine....Thanks again.

Hi, but what if we need to provide an absolute path and not relative and also, what's the difference between the two ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.