根据 WPF 中的条件更改按钮 <Path Data [英] change the button <Path Data based on condition in WPF
本文介绍了根据 WPF 中的条件更改按钮 <Path Data的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何根据按钮点击条件更改图像
How to change the image based on conditions for button click
如果分配的数据源是WindowMin",那么我需要在单击反向时再次将其更改为WindowMax".
if Assigned data source is "WindowMin" than i need to change it to "WindowMax" again on click reverse.
<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>
推荐答案
以下代码适用于上述问题.
Following code is working for the above question.
<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>
这篇关于根据 WPF 中的条件更改按钮 <Path Data的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文