1

アイデアは次のとおりです。DataGridTemplateColumnユーザーがセルを展開してコンテンツ全体を表示したり、セルを折りたたんで最初の行のみを表示したりできるようにするには、展開/折りたたみボタンが必要です。これが私のテンプレートです:

<DataGridTemplateColumn.CellTemplate>
    <DataTemplate>
        <Grid HorizontalAlignment="Stretch" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <local:ExpandCollapseButton />
            <TextBlock x:Name="MyTB" Text="{Binding Body}" Grid.Column="1" TextTrimming="WordEllipsis" />
        </Grid>
    </DataTemplate>
</DataGridTemplateColumn.CellTemplate>

ExpandCollapseButtonUserControlクリックすると + と - のアイコンが切り替わる単純なものです。という名前の読み取り/書き込みboolプロパティがありIsExpandedます。

私は今、簡単なTriggertoExpandCollapseButtonのトリガーを追加しようとしています。これは、TextBlockTextTrimmingプロパティをWordEllipsis折りたたまれた状態に設定しNone、展開された状態に設定するだけですが、それを行う正しい方法がわかりません。上記の Expand コントロールの下に次のコードを追加してみました。

<local:ExpandCollapseButton.Triggers>
    <Trigger Property="IsExpanded" Value="True">
        <Setter TargetName="MyTB" Property="TextTrimming" Value="None" />
    </Trigger>
</local:ExpandCollapseButton.Triggers>

Cannot find the static member 'IsExpandedProperty' on the type 'ContentPresenter'しかし、これは私が理解できないというエラーを出します。

4

1 に答える 1

4

SourceName と TargetName で DataTemplate トリガーを使用します。

<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
    <Grid HorizontalAlignment="Stretch" >
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <local:ExpandCollapseButton x:Name="MyButton"/>
        <TextBlock x:Name="MyTB" Text="{Binding Body}" Grid.Column="1" TextTrimming="WordEllipsis" />
    </Grid>
     <DataTemplate.Triggers>
            <Trigger Property="IsExpanded" Value="True" SourceName="MyButton">
                <Setter Property="TextBlock.TextTrimming" Value="None" TargetName="MyTB"/>
            </Trigger>
        </DataTemplate.Triggers>
</DataTemplate>

ありがとう

于 2013-08-29T05:31:44.020 に答える