2016-07-22 5 views
0

私は文字列の辞書を持っています。これをWPFのDataGridにバインドしたいと思います。WPFカスタムDataColumnヘッダ(ディクショナリ付き)

<DataTemplate DataType="{x:Type DictionaryClass}"> 
     <DataGrid HorizontalAlignment="Stretch" 
        ItemsSource="{Binding StringDictionary}"> 
     </DataGrid> 
</DataTemplate> 

これは、期待通りに2つの列を作成しますが、2つの列にはそれぞれ「Key」と「Value」というヘッダーがあります。私はHeadersVisibilityのプロパティを変更できることを知っています。どうすれば自分のカスタム列見出しを設定できますか?

答えて

2

列の自動生成を無効にし、手動で定義する必要があります。

<DataGrid AutoGenerateColumns="False"> 
    <DataGrid.Columns> 
     <DataGridTextColumn Header="Text 1" Binding="{Binding Key}" /> 
     <DataGridTextColumn Header="Text 2" Binding="{Binding Value}" /> 
    </DataGrid.Columns> 
</DataGrid> 
+0

恐ろしい、ありがとう! –

関連する問題