Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

DataGrid: How to change cell foreground after LoadingRow? RSS

4 replies

Last post Jun 07, 2009 02:03 PM by puneetpriyadarshi

(0)
  • hushaoming

    hushaoming

    Member

    4 Points

    9 Posts

    DataGrid: How to change cell foreground after LoadingRow?

    Jan 06, 2009 07:19 AM | LINK

    In the post: http://silverlight.net/forums/t/42372.aspx I make cell foreground change. After that, when the data in cell is changed, I need change foreground again. But the LoadingRow can not be raising after first load. Does anyone have a good way to do this?

     thanks 

    datagrid DataGridCellStyle Datagrid Cell Focus

  • preishuber

    preishuber

    Contributor

    3572 Points

    658 Posts

    Re: DataGrid: How to change cell foreground after LoadingRow?

    Jan 06, 2009 08:44 AM | LINK

    i would try to use two way databinding and a valueconverter

    http://silverlight.net/forums/p/27465/93474.aspx#93474

    -Hannes

    http://www.ppedv.de
  • hushaoming

    hushaoming

    Member

    4 Points

    9 Posts

    Re: DataGrid: How to change cell foreground after LoadingRow?

    Jan 07, 2009 01:24 AM | LINK

    Thank preishuber.

    Finnally, I use Foreground Binding a property in my dataclass

    In my data class, add ForeColor

        public class MyData : INotifyPropertyChanged
        {
            #region Static Brush
    
            private static Brush _highPriceBrush;
            public static Brush HighPriceBrush
            {
                get
                {
                    if (null == _highPriceBrush)
                        _highPriceBrush = new SolidColorBrush(Colors.Red);
                    return _highPriceBrush;
                }
                set { _highPriceBrush = value; }
            }
    
            private static Brush _lowPriceBrush;
            public static Brush LowPriceBrush
            {
                get
                {
                    if (null == _lowPriceBrush)
                        _lowPriceBrush = new SolidColorBrush(Colors.Blue);
                    return _lowPriceBrush;
                }
                set { _lowPriceBrush = value; }
            }
    
            #endregion
    
            private float _price;
            public float Price
            {
                get { return _price; }
                set
                {
                    _price = value;
                    PropertyChanged(this, new PropertyChangedEventArgs("Price"));
                    PropertyChanged(this, new PropertyChangedEventArgs("ForeColor"));
                }
            }
    
            public Brush ForeColor 
            {
                get
                {
                    if (Price > 100.0f)
                        return _highPriceBrush;
                    else
                        return _lowPriceBrush;
                }
            }
    
            #region INotifyPropertyChanged
    
            public event PropertyChangedEventHandler PropertyChanged;
    
            #endregion
    
        }
    

     in Page.XAML like this:

                        <data:DataGridTemplateColumn Header="Price" IsReadOnly="True">
                            <data:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Price}" Foreground="{Binding ForeColor}" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="5,0,5,0"/>
                                </DataTemplate>
                            </data:DataGridTemplateColumn.CellTemplate>
                        </data:DataGridTemplateColumn>
    

     

    It works, but I think it is not a best way.

     

  • Prashant Agone

    Prashant Agone

    Member

    2 Points

    2 Posts

    Re: DataGrid: How to change cell foreground after LoadingRow?

    May 15, 2009 09:20 AM | LINK

     Hi,

    I changed the background & foreground color of DataGridCell and when I select the click on datagrid row that time the edited cell not show row selection color.

    It is only show the color which I modified 

  • puneetpriyadarshi

    puneetpriyad...

    Member

    28 Points

    17 Posts

    Re: DataGrid: How to change cell foreground after LoadingRow?

    Jun 07, 2009 02:03 PM | LINK

     Try This it might help..

     Thanks

    Puneet