0
我想自定義一個DataGrid。我想在列標題上插入一些內容。我正在嘗試使用ControlTemplate來執行此操作。下面我有我的XAML代碼。我的問題是<ContentPresenter />
不輸出任何東西。當我加載頁面時,after
TextBlock出現在before
TextBlock的正下方,兩者之間沒有任何內容。我想在該空間中顯示列標題。如何自定義WPF Datagrid中列標題的顯示?
<DataGrid ItemsSource="{Binding List}" AutoGenerateColumns="True">
<DataGrid.Template>
<ControlTemplate>
<StackPanel Orientation="Vertical">
<TextBlock>before</TextBlock>
<ContentPresenter /> <!-- outputs nothing -->
<TextBlock>after</TextBlock>
<ItemsPresenter />
</StackPanel>
</ControlTemplate>
</DataGrid.Template>
</DataGrid>
如何顯示before
的TextBlock和after
TextBlock中的列標題?我的列表對象只是一些具有一些公共屬性的泛型類的BindingList。