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

Problem binding row's Foreground property

2 Answers 61 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Michael Maddux
Top achievements
Rank 1
Michael Maddux asked on 17 Aug 2010, 08:50 PM
This is a problem where I'm trying to bind the Foreground property of a grid row to an entity property.

The color gets set correctly when the rows are loaded and entities created, but when the bound property on an entity gets changed, the color doesn't change.

I'm setting up the binding in the GridView's RowLoaded event:

 

private void ReferenceGrid_RowLoaded(object sender, RowLoadedEventArgs e)
{
    Binding binding = new Binding("Status");
    binding.Mode = BindingMode.OneWay;
    e.Row.SetBinding(GridViewRowItem.ForegroundProperty, binding);
}

 

 


The entity's Status property (bound above) is a SolidColorBrush

ColorBrushes are defined this way

 

 

<SolidColorBrush x:Key="GreenColorBrush" Color="Green"/> 
<SolidColorBrush x:Key="BlueColorBrush" Color="Blue"/> 
<SolidColorBrush x:Key="BlackColorBrush" Color="Black"/> 
<SolidColorBrush x:Key="OrangeColorBrush" Color="Orange"/> 
<SolidColorBrush x:Key="RedColorBrush" Color="Red"/> 

 

 

 

And here is the definition of the Status property on my entity...

public SolidColorBrush Status
{
    get
    {
        if (!ActiveFlag)
        {
            return (SolidColorBrush App.Current.Resources["OrangeColorBrush"];                  
        }
        return (SolidColorBrush)App.Current.Resources["RedColorBrush"];
    }
}

 

 

 



When the rows are loaded, the framework calls the "getter" on the Status property.  The rows on the screen are correctly colored, either orange or red.

The user can change the "ActiveFlag" via a checkbox on the row.

When the user does this, my partial method OnActiveFlagChanged is called.  Here is that method...

 

 

 

partial void OnActiveFlagChanged()
{
    RaisePropertyChanged("Status");
}

 

 

I have verified in the debugger that this method gets called.

Then the framework accesses the "getter" for the Status property, which is expected since the property changed event for this property was just raised.

I have verified in the debugger that the Status property's get method is called, and also that the new color brush is returned from the property.

This all works as expected.  The only problem is that the color on the screen doesn't change. 

What am I missing?

Thanks,

Mike Maddux

 

 

2 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 18 Aug 2010, 09:21 AM
Hello Michael Maddux,

I have replicated your scenario in the attached sample project and all seems fine.

Hope it helps.


Best wishes,
Milan
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Michael Maddux
Top achievements
Rank 1
answered on 19 Aug 2010, 03:49 PM
Thanks for the quick response!
Tags
GridView
Asked by
Michael Maddux
Top achievements
Rank 1
Answers by
Milan
Telerik team
Michael Maddux
Top achievements
Rank 1
Share this question
or