LoginSignup
2
2

More than 5 years have passed since last update.

ListViewのカラムスタイルを動的に切り替える

Posted at

方法

以下のようにして成功した。

<GridViewColumn>
    <GridViewColumn.CellTemplate>
        <DataTemplate>
            <ContentControl Content={Binding}>
                <ContentControl.Style>
                    <Style TargetType="{x:Type ContentControl}">
                        <Style.Triggers>
                            <DataTrigger Binding="..." Value="...">
                                <Setter Property="ContentTemplate">
                                    <Setter.Value>
                                        <DataTemplate>
                                        ...
                                        </DataTemplate>
                                    </Setter.Value>
                                </Setter>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ContentControl.Style>
            </ContentControl>
        </DataTemplate>
    </GridViewColumn.CellTemplate>
</GridViewColumn>

注意

上記で、<ContentControl>タグでContent={Binding}が無いとバインドがうまく行かないようだ。

参考

  1. Change ListView CellTemplate based on state of item - Stack Overflow
  2. How to Bind To Data within a Datatemplate of a ContentControl - Stack Overflow
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2