This is a migrated thread and some comments may be shown as answers.

[Solved] Retrieve Property value from a Style

2 Answers 88 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Voss Grose
Top achievements
Rank 1
Voss Grose asked on 30 Jul 2009, 12:10 AM
Is it possible to retrieve the Value of Property that is a child of a Style.Setter node from code?

I was trying to do something like this to found out what the background color of a row was based on the style, but couldn't figure it out:
//Setter backgroundStyleColor = (from setter in row.Style.Setters where setter.???? == "BackGround" select setter).FirstOrDefault() as Setter;

Here are my styles:


   <UserControl.Resources>
        <Style TargetType="gridView:GridViewRow" x:Key="RowStyle">
            <Setter Property="MinHeight" Value="20"/>
            <Setter Property="BackGround" Value="#FFFFFF"/>
        </Style>
        <Style TargetType="gridView:GridViewRow" x:Key="AlternateRowStyle">
            <Setter Property="MinHeight" Value="20"/>
            <Setter Property="BackGround" Value="#EDF4FA"/>
        </Style>
        <Style x:Key="GroupRowStyle" TargetType="gridView:GridViewGroupRow">
            <Setter Property="HorizontalAlignment" Value="Left" />
        </Style>
    </UserControl.Resources>

Thanks.

2 Answers, 1 is accepted

Sort by
0
Accepted
Rossen Hristov
Telerik team
answered on 31 Jul 2009, 11:14 AM
Hi Voss Grose,

Unfortunately Silverlight does not support this. I could get the correct setter, i.e. the one for the background but its value is always null, which is a Silverlight glitch and I hope that MS will address this sooner or later.

The only thing that I can think of is to use a static resource for the Setter.Value and then use this same resource in your code-behind, since I suppose that you want to color something else in the same color as the row:

    <UserControl.Resources> 
        <SolidColorBrush x:Key="MySharedBrush" Color="Red"/> 
        <Style TargetType="gridView:GridViewRow" x:Key="RowStyle"
            <Setter Property="Background" Value="{StaticResource MySharedBrush}"/> 
        </Style> 
    </UserControl.Resources> 
 

Or you can read the value from the GridViewRow.Background property itself. That's all about I can think of. If this does not help -- can you please share why exactly do you need to read the value from the setter and I will try to think of a workaround.

Best wishes,
Ross
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Voss Grose
Top achievements
Rank 1
answered on 31 Jul 2009, 02:51 PM
Thanks Ross....I found a work around similar to what you suggested.

It wasn't a big deal, but thought I would try to do it the right way first before hacking it out.

thanks.
Tags
GridView
Asked by
Voss Grose
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Voss Grose
Top achievements
Rank 1
Share this question
or