更改按钮<;WPF中基于条件的路径数据

更改按钮<;WPF中基于条件的路径数据,wpf,xaml,Wpf,Xaml,如何根据单击按钮的条件更改图像 如果指定的数据源为“WindowMin”,则我需要在单击“反转”时再次将其更改为“WindowMax” <Button DockPanel.Dock="Right" Style="{StaticResource WindowButton}" Command="{StaticResource MaximizeCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Fin

如何根据单击按钮的条件更改图像

如果指定的数据源为“WindowMin”,则我需要在单击“反转”时再次将其更改为“WindowMax”

<Button DockPanel.Dock="Right"  Style="{StaticResource WindowButton}" Command="{StaticResource MaximizeCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}">
                        <Path Data="{Binding Data, Source={StaticResource WindowMax}}" />
                    </Button>

<Style TargetType="{x:Type Button}" x:Key="WindowButton">
    <Setter Property="Height" Value="17"/>
    <Setter Property="Width" Value="25"/>
    <!--<Setter Property="Background" Value="#FF414141"/>-->
    <Setter Property="Foreground" Value="{StaticResource WindowForeColor}"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Button}">
                <Border Background="Transparent">
                    <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter Property="Background" Value="{StaticResource WindowButtonColor}"/>
                        <Setter Property="Foreground" Value="{StaticResource WindowColor}"/>
                    </Trigger>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="BitmapEffect">
                            <Setter.Value>
                                <DropShadowBitmapEffect Direction="302" Opacity="0.4" ShadowDepth="2" Softness="0.5"/>
                            </Setter.Value>
                        </Setter>
                        <Setter Property="Background" Value="{StaticResource WindowButtonOverColor}"/>
                        <Setter Property="Foreground" Value="{StaticResource WindowForeHighlightColor}"/>
                    </Trigger>
                    <Trigger Property="IsPressed" Value="True">
                        <Setter Property="Background" Value="{StaticResource WindowButtonPressedColor}"/>
                        <Setter Property="Foreground" Value="{StaticResource WindowForeColor}"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

以下代码适用于上述问题

<Geometry x:Key="MaxIcon">
    F1 M 43,48L 46,48L 46,57L 19,57L 19,34L 32,34L 32,40L 22,40L 22,54L 43,54L 43,48 Z M 21,19L 57,19L 57,50L 49,50L 49,46L 53,46L 53,27L 25,27L 25,32L 21,32L 21,19 Z M 37.75,30L 50,30L 50,42.25L 46,46.25L 46,37.25L 38,45.25L 34.75,42L 42.75,34L 33.75,34L 37.75,30 Z        
</Geometry>
<Geometry x:Key="MinIcon">
    F1 M 33,48L 33,54L 54,54L 54,40L 45,40L 45,34L 57,34L 57,57L 30,57L 30,48L 33,48 Z M 55,19L 55,31L 52,31L 52,27L 23,27L 23,46L 27,46L 27,49L 20,49L 20,19L 55,19 Z M 25.75,41L 34.75,41L 26.75,33L 30,29.75L 38,37.75L 38,28.75L 42,32.75L 42,45L 29.75,45L 25.75,41 Z        
</Geometry>

<Path.Style>
            <Style TargetType="Path">
                <Setter Property="Data" Value="{StaticResource MaxIcon}"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding WindowState, RelativeSource={RelativeSource AncestorType=Window}}" 
                                 Value="Maximized">
                        <Setter Property="Data" Value="{StaticResource MinIcon}"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style> 
        </Path.Style>

F1 M 43,48L 46,48L 46,57L 19,57L 19,34L 32,34L 32,40L 22,40L 22,54L 43,54L 43,48Z M 21,19L 57,19L 57,50L 49,50L 49,46L 53,46L 53,27L 25,32L 21,32L 21,19Z M 37.75,30L 50,42.25L 46,46.25L 46,37.25L 38,45.25L 34.75,42L 42.75,34L 33.75,30
F1 M 33,48L 33,54L 54,54L 54,40L 45,40L 45,34L 57,34L 57,57L 30,57L 30,48L 33,48Z M 55,19L 55,31L 52,31L 52,27L 23,27L 23,46L 27,46L 27,49L 20,49L 20,19L 55,19Z M 25.75,41L 26.75,33L 30,29.75L 38,37.75L 38,28.75L 42,32.75L 42,45L 29.75,45L 25,41

以下代码适用于上述问题

<Geometry x:Key="MaxIcon">
    F1 M 43,48L 46,48L 46,57L 19,57L 19,34L 32,34L 32,40L 22,40L 22,54L 43,54L 43,48 Z M 21,19L 57,19L 57,50L 49,50L 49,46L 53,46L 53,27L 25,27L 25,32L 21,32L 21,19 Z M 37.75,30L 50,30L 50,42.25L 46,46.25L 46,37.25L 38,45.25L 34.75,42L 42.75,34L 33.75,34L 37.75,30 Z        
</Geometry>
<Geometry x:Key="MinIcon">
    F1 M 33,48L 33,54L 54,54L 54,40L 45,40L 45,34L 57,34L 57,57L 30,57L 30,48L 33,48 Z M 55,19L 55,31L 52,31L 52,27L 23,27L 23,46L 27,46L 27,49L 20,49L 20,19L 55,19 Z M 25.75,41L 34.75,41L 26.75,33L 30,29.75L 38,37.75L 38,28.75L 42,32.75L 42,45L 29.75,45L 25.75,41 Z        
</Geometry>

<Path.Style>
            <Style TargetType="Path">
                <Setter Property="Data" Value="{StaticResource MaxIcon}"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding WindowState, RelativeSource={RelativeSource AncestorType=Window}}" 
                                 Value="Maximized">
                        <Setter Property="Data" Value="{StaticResource MinIcon}"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style> 
        </Path.Style>

F1 M 43,48L 46,48L 46,57L 19,57L 19,34L 32,34L 32,40L 22,40L 22,54L 43,54L 43,48Z M 21,19L 57,19L 57,50L 49,50L 49,46L 53,46L 53,27L 25,32L 21,32L 21,19Z M 37.75,30L 50,42.25L 46,46.25L 46,37.25L 38,45.25L 34.75,42L 42.75,34L 33.75,30
F1 M 33,48L 33,54L 54,54L 54,40L 45,40L 45,34L 57,34L 57,57L 30,57L 30,48L 33,48Z M 55,19L 55,31L 52,31L 52,27L 23,27L 23,46L 27,46L 27,49L 20,49L 20,19L 55,19Z M 25.75,41L 26.75,33L 30,29.75L 38,37.75L 38,28.75L 42,32.75L 42,45L 29.75,45L 25,41

创建两条路径并触发其可见性创建两条路径并触发其可见性