开发者

How to reference "PreviousData" when setting ContentPresenter.Style

开发者 https://www.devze.com 2023-04-12 23:58 出处:网络
In the following code I am trying to set the style of the first item in my collection to one template and the rest to a different template by checking if the PreviousElement is null.I think my relativ

In the following code I am trying to set the style of the first item in my collection to one template and the rest to a different template by checking if the PreviousElement is null. I think my relativesource is incorrect because the trigger condition is always true. What should the path be?

    <DataTemplate x:Key="RowItemTemplate">
        <ContentPresenter Content="{Binding}">
            <ContentPresenter.Style>
                <Style TargetType="{x:Type ContentPresenter}">
   开发者_运维百科                 <Setter Property="ContentTemplate" Value="{StaticResource ComparisonTemplate}"/>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource PreviousData}}" Value="{x:Null}">
                            <Setter Property="ContentTemplate" Value="{StaticResource SourceTemplate}"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </ContentPresenter.Style>
        </ContentPresenter>
    </DataTemplate>


I created an interface that has a bool to determine which template a particular element should use:

    <DataTemplate x:Key="RowItemTemplate">
        <ContentPresenter Content="{Binding}">
            <ContentPresenter.Style>
                <Style TargetType="{x:Type ContentPresenter}">
                    <Setter Property="ContentTemplate" Value="{StaticResource ComparisonTemplate}"/>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding DataItem}" Value="true">
                            <Setter Property="ContentTemplate" Value="{StaticResource SourceTemplate}"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </ContentPresenter.Style>
        </ContentPresenter>
    </DataTemplate>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号