这与我的previous question相关,因为它处理的是同一段代码;现在我已经完成了按钮背景的改变,问题是现在我需要实现相同的代码,但不是用于ButtonPressed,而是用于点击按钮。我在代码中添加了点击处理程序,但它不起作用 - 背景没有改变。我尝试了不同的方法,即使使用位图和图像资源,但它不工作,更改根本不会发生。现在我想要实现背景图像的更改,但它需要在XAML文件中完成,而不是在.cs中完成。再次代码:在WPF内部的WPF控件上实现点击事件
<Button x:Class="proba4.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="120" d:DesignWidth="300" IsEnabled="True">
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<Image Name="Normal" Source="C:\stuff\off_button.gif"/>
<Image Name="Pressed" Source="C:\stuff\on_button.gif" Visibility="Hidden"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="Normal" Property="Visibility" Value="Hidden"/>
<Setter TargetName="Pressed" Property="Visibility" Value="Visible"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
请注意,我已经看过用于单击某个按钮属性,但有没有,我的一切互联网上找到的实现正在处理中的.cs加入Button_Click方法该控件的代码,因为这不适合我,我需要找到另一种方式 - 希望像使用WPF完全实现的点击控制。 我想这是微妙的,但我将不胜感激任何帮助,谢谢。