【问题标题】:How to change DataRow style in Silverlight如何在 Silverlight 中更改 DataRow 样式
【发布时间】:2014-04-21 16:46:00
【问题描述】:

我已经关注 XAML 来更改 Cell

<sdk:DataGrid  Margin="10" Grid.Row="1" IsReadOnly="True" AutoGenerateColumns="False" x:Name="dgrdDataGrid" GridLinesVisibility="All">
              <sdk:DataGrid.Columns>
                <sdk:DataGridTextColumn Binding="{Binding FirstName}" Header="First Name" />
                <sdk:DataGridTextColumn Binding="{Binding LastName}" Header="Last Name" />
                <sdk:DataGridTemplateColumn Header="Subscribed" Width="*" SortMemberPath="IsSubscribed">
                    <sdk:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal" >
                                <TextBlock  Text="No Information" x:Name="txtTextBlock" Width="100" VerticalAlignment="Center" Margin="5"/>
                                <i:Interaction.Triggers>
                                    <ei:DataTrigger  Binding="{Binding Path=IsSubscribed}" Value="true">

                                        <ei:ChangePropertyAction TargetObject="{Binding ElementName=txtTextBlock}"  TargetName="Text" Value="Verified" PropertyName="Text"/>
                                        <ei:ChangePropertyAction TargetObject="{Binding ElementName=txtTextBlock}"  TargetName="Foreground" Value="Red" PropertyName="Foreground"/>
                                        <ei:ChangePropertyAction TargetObject="{Binding ElementName=txtTextBlock}"  TargetName="Foreground" PropertyName="FontWeight">
                                            <ei:ChangePropertyAction.Value>
                                                <FontWeight>Bold</FontWeight>
                                            </ei:ChangePropertyAction.Value>
                                        </ei:ChangePropertyAction>
                                    </ei:DataTrigger>
                                    <ei:DataTrigger  Binding="{Binding Path=IsSubscribed}" Value="false">
                                        <ei:ChangePropertyAction TargetObject="{Binding ElementName=txtTextBlock}"  TargetName="Text" Value="Not Verified" PropertyName="Text"/>
                                    </ei:DataTrigger>
                                </i:Interaction.Triggers>
                            </StackPanel>
                        </DataTemplate>
                    </sdk:DataGridTemplateColumn.CellTemplate>
                </sdk:DataGridTemplateColumn>
            </sdk:DataGrid.Columns>
        </sdk:DataGrid>

现在我想更改IsSubscribed = true 的背景,比如说使用黄色颜色。

是否有可能基于我拥有的 XAML 以某种方式做到这一点?

【问题讨论】:

    标签: silverlight xaml datagrid


    【解决方案1】:

    如果你没有关注 MVVM,添加如下事件

     void dgrdDataGrid_LoadingRow(object sender, DataGridRowEventArgs e)
    {
        DataGridRow row = e.Row;
        var c = row.DataContext as YourDataGridOjbect;         
        if (c != null && c.IsSubscribed == true)
            e.Row.Foreground = new SolidColorBrush(Colors.Yellow);
        else
            e.Row.Foreground = new SolidColorBrush(Colors.Red);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多