1

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>
3
Contributors
3
Replies
11
Views
4 Years
Discussion Span
Last Post by aatish2327
1

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>
1

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.

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.