0

是否可以将如下的 DataTrigger 绑定设置为重复绑定但绑定路径不同的样式?

<Button Grid.Row="2" Grid.Column="1"   VerticalAlignment="Center" Background="{Binding Dyes[4].DyeBrush}">
        <Button.Style>
            <Style TargetType="Button" BasedOn="{StaticResource Dye}">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Path=Dyes[4].IsReferenceDye}" Value="True">
                        <Setter Property="Content" Value="R" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </Button.Style>
    </Button>

    <Button Grid.Row="3" Grid.Column="1"  VerticalAlignment="Center" Background="{Binding  Dyes[5].DyeBrush}">
        <Button.Style>
            <Style TargetType="Button" BasedOn="{StaticResource Dye}">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Path=Dyes[5].IsReferenceDye}" Value="True">
                        <Setter Property="Content" Value="R" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </Button.Style>
    </Button>
4

1 回答 1

0

让你的风格喜欢

<Style x:Key="ButtonStyle" TargetType="Button" BasedOn="{StaticResource Dye}">
        <Style.Triggers>
            <DataTrigger Binding="{Binding Path=IsReferenceDye}" Value="True">
                <Setter Property="Content" Value="R" />
            </DataTrigger>
        </Style.Triggers>
    </Style> 

并将其用作

<Button Grid.Row="3" Grid.Column="1" 
            DataContext="{Binding Dyes[5]}" 
            Style="{StaticResource ButtonStyle}"
            VerticalAlignment="Center" Background="{Binding  Dyes[5].DyeBrush}"/>

希望这可以帮助。

于 2012-11-09T09:55:20.830 回答