none
DataGridRow Foreground Color Change (Implement in MVVM)

    Question

  • Hi,

    Can somebody help me how to Change the color of a grid row text while loading. I know how to do in RowLoading event but no idea how in MVVM.

    ClassItem item = e.Row.DataContext as ClassItem;
                if ((item != null) && (item.Note.Trim() == "Something"))
                    e.Row.Foreground = new SolidColorBrush(Colors.Red);
                else if((item != null) && (item.1 == 0) && (item.2 == 0))
                    e.Row.Foreground = new SolidColorBrush(Colors.Gray);
                else
                    e.Row.Foreground = new SolidColorBrush(Colors.Black);


     

    This i have done inside the LoadingRow event n it works fine.

    Thursday, September 02, 2010 10:57 AM

Answers

  • u can use triggers for it:

    <sdk:DataGrid AutoGenerateColumns="False" Height="213" HorizontalAlignment="Left" Name="dataGrid1" VerticalAlignment="Top" Width="408" >
    
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="LoadingRow">
                        <i:InvokeCommandAction CommandName="{Binding LoadingRowCommand}" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
    
            </sdk:DataGrid>
    
    where i is xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"  


    u can refer to this thread for further readings:

    http://forums.silverlight.net/forums/p/194515/453706.aspx 

    Friday, September 03, 2010 2:11 AM

All replies

  • u can use triggers for it:

    <sdk:DataGrid AutoGenerateColumns="False" Height="213" HorizontalAlignment="Left" Name="dataGrid1" VerticalAlignment="Top" Width="408" >
    
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="LoadingRow">
                        <i:InvokeCommandAction CommandName="{Binding LoadingRowCommand}" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
    
            </sdk:DataGrid>
    
    where i is xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"  


    u can refer to this thread for further readings:

    http://forums.silverlight.net/forums/p/194515/453706.aspx 

    Friday, September 03, 2010 2:11 AM
  • Ya you are  rite i can raise the command but how would i do those operations in ViewModel like (e.Row.Foreground)

    Friday, September 03, 2010 3:21 AM
  • Use CommandParameter  property

    Friday, September 03, 2010 7:49 AM
  • What i should give to get this e.Row 

    Saturday, September 04, 2010 3:08 AM