【问题标题】:Issue setting foreground of DataGridRow in Silverlight在 Silverlight 中设置 DataGridRow 的前景问题
【发布时间】:2011-04-28 11:15:27
【问题描述】:

我确实有我简单的 Silverlight 任务:

在 DataGrid 中显示供应商对象列表。
如果供应商“停用”(由供应商的属性 IsDeactivated 指示)显示手形图标并将前景色设置为灰色。否则将前景色设置为蓝色。
该行应如下所示:

指定的列是模板列,如下所示:

            <sdk:DataGridTemplateColumn IsReadOnly="True">
                <sdk:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock Padding="3" Text="{Binding City}" />
                    </DataTemplate>
                </sdk:DataGridTemplateColumn.CellTemplate>
            </sdk:DataGridTemplateColumn>

为了在分配数据源后设置前景色,我实现了 LoadingRowUndloadingRow 事件:

        private void LoadingDataGridRow(object sender, DataGridRowEventArgs e)
    {
        var supplier = (Supplier)e.Row.DataContext;
        e.Row.Foreground = supplier.IsDeactivated ? new SolidColorBrush(Colors.Gray) : new SolidColorBrush(Color.FromArgb(255, 65, 85, 155));
    }

    private void UnLoadingDataGridRow(object sender, DataGridRowEventArgs e)
    {
        var supplier = (Supplier)e.Row.DataContext;
        e.Row.ClearValue(ForegroundProperty);
    }

但是,当我现在将 IsDeactivated 更改为 true 时,手形图标是不可见的 - 根据需要 - 但是,前景色仍然是灰色的:

我已经尝试通过 ConverterPropertyChangeTrigger 方法解决此问题,但是,这会覆盖为 MouseOver选中

我听说这可能与 DataGrid 虚拟化 有关?

有人知道如何解决这个问题吗?

【问题讨论】:

    标签: c# silverlight xaml datagrid styling


    【解决方案1】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-16
      • 2013-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-21
      • 1970-01-01
      相关资源
      最近更新 更多