Skip to main content

Microsoft Silverlight

Answered Question DataGrid: How to change cell foreground after LoadingRow?RSS Feed

(0)

hushaoming
hushaoming

Member

Member

4 points

9 Posts

DataGrid: How to change cell foreground after LoadingRow?

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 

preishuber
preishuber

Contributor

Contributor

3570 points

655 Posts

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

i would try to use two way databinding and a valueconverter

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

-Hannes

http://www.preishuber.net http://weblogs.asp.net/hpreishuber

hushaoming
hushaoming

Member

Member

4 points

9 Posts

Answered Question

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

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

Member

Member

2 points

2 Posts

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

 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
puneetpr...

Member

Member

28 points

17 Posts

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

 Try This it might help..

 Thanks

Puneet

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities