2

私は次のものを持っていますDataTemplate

<DataTemplate x:Key="ButtonTemplate">
    <Button Click="Cell_Click">
        <Button.Template>
            <ControlTemplate TargetType="{x:Type Button}">
                <TextBlock x:Name="TBlock" />
            </ControlTemplate>
        </Button.Template>
    </Button>
</DataTemplate>

そして、これDataTemplateを として使用しますが、新しい列を追加するときにのプロパティをGridViewColumn.CellTemplate動的にバインドする必要があります。TextTextBlock

GridViewColumn column = new GridViewColumn();
column.CellTemplate = Resources["ButtonTemplate"] as DataTemplate;
// How to get the TBlock (TextBlock) of CellTemplate and bind its property here?
MyGridView.Columns.Add(column);

私は何をしなければなりませんか?ありがとう。

4

2 に答える 2

0

TextBlock の Loaded-Event に EventHandler をアタッチし、そこにバインディングを作成できます (十分な情報であれば、TextBlock の DataContext に基づいて)。

于 2012-09-30T11:52:22.410 に答える
0

テンプレートを変更することは忘れて、コードで最初から作成することをお勧めします (またはXamlReader.Parse、バインディング コードを動的に挿入した XAML 文字列を使用できます)。

于 2012-09-30T13:13:26.253 に答える