【问题标题】:Silverlight Datagrid: Setting background of a template cell with custom behaviorSilverlight Datagrid:使用自定义行为设置模板单元格的背景
【发布时间】:2011-04-29 21:34:33
【问题描述】:

我有一个自定义的DataGridDataGridTemplateColumns 混合在一起,以及从这个答案Silverlight Datagrid: Highlight an entire column when that column is sorted 派生的自定义行为。我遇到的问题是任何 DataGridTemplateColumn 的单元格都没有选择“突出显示”。用于自定义列的单元格模板具有如下所示的结构。任何人都知道为什么没有应用背景突出显示?我一直在为这个问题绞尽脑汁。

<DataTemplate>
    <Grid>
        <Border VerticalAlignment='Stretch' Margin='1' Background='Transparent'>
            <TextBlock VerticalAlignment='Center' Text='{Binding Path=Variable}' />
        </Border>
    </Grid>
</DataTemplate>

【问题讨论】:

    标签: c# silverlight xaml datagrid datagridtemplatecolumn


    【解决方案1】:

    为了解决这个问题,我最终需要在继承自 DataGridTemplateColumn 的自定义列类上创建一个名为 Backgroundstring DependencyProperty。此外,在行为中,我必须检查列的类型。

    之前,我只是将 CollectionChanged 事件处理程序中的列设置为 DataGridBoundColumn。现在我检查它是否真的是那种类型,或者它是否是 DataGridTemplateColumn。 DataGridTemplateColumn检查绑定路径的方式不同,区别如下图

    DataGridBoundColumn:boundColumn.Binding.Path.Path DataGridTemplateColumn:boundColumn.SortMemberPath

    我必须做的最后一个调整是更改DataTemplate 的结构,使其现在看起来如下所示,基本上就是以不同的方式设置颜色。

    <DataTemplate>
        <Grid>
            <Border>
                <Border.Background>
                    <SolidColorBrush Color='{0}' />
                </Border.Background>
                <TextBlock VerticalAlignment='Center' Text='{Binding Path=Variable}' />
            </Border>
        </Grid>
    </DataTemplate>
    

    【讨论】:

      猜你喜欢
      • 2012-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-12
      • 1970-01-01
      • 1970-01-01
      • 2018-04-14
      • 2014-06-17
      相关资源
      最近更新 更多