WPF中具有不同高光图像的多个切换按钮图像
我对WPF非常陌生,需要一些关于为什么它不能正常工作的指针 我正在尝试创建一个最大化按钮,当单击该按钮时,该按钮将变为还原按钮。我认为一个具有两种不同风格的切换按钮可以在代码中进行更改。我第一次尝试使最大化按钮工作,但遇到了一个问题。我发现错误“System.Windows.Controls.Image”不是Setter上“System.Windows.Controls.Image.Source”属性的有效值。在我的xaml中。我似乎没有完全理解一些事情。任何帮助都会非常有用:) 瑞安WPF中具有不同高光图像的多个切换按钮图像,wpf,image,xaml,togglebutton,Wpf,Image,Xaml,Togglebutton,我对WPF非常陌生,需要一些关于为什么它不能正常工作的指针 我正在尝试创建一个最大化按钮,当单击该按钮时,该按钮将变为还原按钮。我认为一个具有两种不同风格的切换按钮可以在代码中进行更改。我第一次尝试使最大化按钮工作,但遇到了一个问题。我发现错误“System.Windows.Controls.Image”不是Setter上“System.Windows.Controls.Image.Source”属性的有效值。在我的xaml中。我似乎没有完全理解一些事情。任何帮助都会非常有用:) 瑞安 您不想在
您不想在鼠标悬停时更改图像。我在项目中将图像添加到名为images的文件夹中,并将图像上的构建操作设置为Resource
<Window.Resources>
<Image x:Key="minImage" Source="/Images/min.png" Height="16" Width="16" />
<Image x:Key="maxImage" Source="/Images/max.png" Height="16" Width="16" />
<Style TargetType="{x:Type ToggleButton}" x:Key="minMaxButtonStyle">
<Setter Property="Content" Value="{DynamicResource minImage}" />
<Style.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Content" Value="{DynamicResource maxImage}" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<StackPanel>
<ToggleButton Style="{StaticResource minMaxButtonStyle}" />
</StackPanel>
</Window>
您不想在鼠标上方更改图像。我在项目中将图像添加到名为images的文件夹中,并将图像上的构建操作设置为Resource
<Window.Resources>
<Image x:Key="minImage" Source="/Images/min.png" Height="16" Width="16" />
<Image x:Key="maxImage" Source="/Images/max.png" Height="16" Width="16" />
<Style TargetType="{x:Type ToggleButton}" x:Key="minMaxButtonStyle">
<Setter Property="Content" Value="{DynamicResource minImage}" />
<Style.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Content" Value="{DynamicResource maxImage}" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<StackPanel>
<ToggleButton Style="{StaticResource minMaxButtonStyle}" />
</StackPanel>
</Window>
确实有效,但我使用IsMouseOver创建高光,而不是更改图像。每个州有2个图像,一个普通图像和一个鼠标悬停图像。我可以通过将设置为并让setter属性源直接转到图像来让我的工作。这确实有效,但我使用IsMouseOver创建高光,而不是更改图像。每个州有2个图像,一个普通图像和一个鼠标悬停图像。我能够通过设置to使我的工作,并让setter属性源直接转到图像。
<Window.Resources>
<Image x:Key="minImage" Source="/Images/min.png" Height="16" Width="16" />
<Image x:Key="maxImage" Source="/Images/max.png" Height="16" Width="16" />
<Style TargetType="{x:Type ToggleButton}" x:Key="minMaxButtonStyle">
<Setter Property="Content" Value="{DynamicResource minImage}" />
<Style.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Content" Value="{DynamicResource maxImage}" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<StackPanel>
<ToggleButton Style="{StaticResource minMaxButtonStyle}" />
</StackPanel>
</Window>