2010-10-24 72 views
0

我有一個自定義DataGridDataGridTemplateColumns混合在一起並且從此答案導出了一個自定義行爲Silverlight Datagrid: Highlight an entire column when that column is sorted。我遇到的問題是任何DataGridTemplateColumn的單元格都沒有選擇「高亮」。用於自定義列的單元格模板的結構如下所示。任何人有任何想法爲什麼背景突出顯示沒有被應用?一段時間以來,我一直在對這個問題大發雷霆。Silverlight Datagrid:使用自定義行爲設置模板單元格的背景

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

回答

0

爲了解決這個問題,我最終需要建立在從DataGridTemplateColumn繼承自定義列類string DependencyProperty稱爲Background。此外,在行爲中,我必須檢查該列是什麼類型。

之前,我只想將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>