5

DataGridTemplateColumnさまざまなオブジェクトとプロパティを持つアプリケーション全体で使用できるように、共通の を作成する必要があります。

これが私のプロジェクトで使用するサンプルコードです

<DataGridTemplateColumn Width="100*">
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Path=Age}"/>
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>   
    <DataGridTemplateColumn.CellEditingTemplate>
        <DataTemplate>
            <TextBox Text="{Binding Path=Age}"/>
        </DataTemplate>
    </DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>

DataTemplateを配置してコード内app.xamlで参照できるように、汎用バージョンのコードが必要です。

4

1 に答える 1

7

DataGridTemplateColumn直接テンプレート化することはできません。しかし幸いなことに、セルにはグローバル テンプレートを使用できます。例を見てみましょう:

App.xaml

<Application.Resources>

    <DataTemplate x:Key="CellEdintingTemplate">
        <TextBox Text="{Binding Path=Age}" />
    </DataTemplate>
    <DataTemplate x:Key="CellTemplate">
        <TextBlock Text="{Binding Path=Age}" />
    </DataTemplate>

</Application.Resources>

使用する

    <DataGrid>
        <DataGrid.Columns>
            <DataGridTemplateColumn 
                 CellEditingTemplate="{StaticResource CellEdintingTemplate}" 
                 CellTemplate="{StaticResource CellTemplate}" />
        </DataGrid.Columns>
    </DataGrid>
于 2012-04-28T09:16:24.967 に答える