如何通过触发器更改WrapPanel的方向属性?

问题描述 投票:0回答:1

我想知道如何通过触发器更改WrapPanel方向属性。

我使用触发器来更改环绕面板方向属性,但不起作用。

<WrapPanel Orientation="Horizontal">
    <WrapPanel.Style>
        <Style TargetType="WrapPanel">
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="true">
                    <Setter Property="Background" Value="Red"/>
                    <Setter Property="Orientation" Value="Vertical"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </WrapPanel.Style>
    <Button Content="button1" Margin="10"/>
    <Button Content="button2" Margin="10"/>
</WrapPanel>

我希望按钮为垂直按钮,背景为红色,但是结果是水平按钮和红色背景。背景已正确更改,但方向未更改。

wpf xaml triggers orientation
1个回答
0
投票

通过样式设置器设置默认的方向值。 Orientation="Horizontal"是本地值,无法通过样式触发器重置

<WrapPanel>
    <WrapPanel.Style>
        <Style TargetType="WrapPanel">
            <Setter Property="Orientation" Value="Horizontal"/>
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="true">
                    <Setter Property="Background" Value="Red"/>
                    <Setter Property="Orientation" Value="Vertical"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </WrapPanel.Style>
    <Button Content="button1" Margin="10"/>
    <Button Content="button2" Margin="10"/>
</WrapPanel>
© www.soinside.com 2019 - 2024. All rights reserved.