Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit DataGrid: How to change cell foreground after LoadingRow?
4 replies. Latest Post by puneetpriyadarshi on June 7, 2009.
(0)
hushaoming
Member
4 points
9 Posts
01-06-2009 3:19 AM |
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
Contributor
3570 points
655 Posts
01-06-2009 4:44 AM |
i would try to use two way databinding and a valueconverter
http://silverlight.net/forums/p/27465/93474.aspx#93474
01-06-2009 9:24 PM |
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...
2 points
2 Posts
05-15-2009 5:20 AM |
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
puneetpr...
28 points
17 Posts
06-07-2009 10:03 AM |
Try This it might help..
Thanks
Puneet