111,123
社区成员
发帖
与我相关
我的任务
分享
namespace MyDemo
{
public class ImageToggleButton : ToggleButton
{
static ImageToggleButton()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(ImageToggleButton), new FrameworkPropertyMetadata(typeof(ImageToggleButton)));
Check_NormalStateProperty = DependencyProperty.Register("Check_NormalState", typeof(string), typeof(ImageToggleButton));
Check_MouseOverStateProperty = DependencyProperty.Register("Check_MouseOverState", typeof(string), typeof(ImageToggleButton));
Check_PressedStateProperty = DependencyProperty.Register("Check_PressedState", typeof(string), typeof(ImageToggleButton));
Uncheck_NormalStateProperty = DependencyProperty.Register("Uncheck_NormalState", typeof(string), typeof(ImageToggleButton));
Uncheck_MouseOverStateProperty = DependencyProperty.Register("Uncheck_MouseOverState", typeof(string), typeof(ImageToggleButton));
Uncheck_PressedStateProperty = DependencyProperty.Register("Uncheck_PressedState", typeof(string), typeof(ImageToggleButton));
}
public string Check_NormalState
{
get { return (string)GetValue(Check_NormalStateProperty); }
set { SetValue(Check_NormalStateProperty, value); }
}
public string Check_MouseOverState
{
get { return (string)GetValue(Check_MouseOverStateProperty); }
set { SetValue(Check_MouseOverStateProperty, value); }
}
public string Check_PressedState
{
get { return (string)GetValue(Check_PressedStateProperty); }
set { SetValue(Check_PressedStateProperty, value); }
}
public string Uncheck_NormalState
{
get { return (string)GetValue(Uncheck_NormalStateProperty); }
set { SetValue(Uncheck_NormalStateProperty, value); }
}
public string Uncheck_MouseOverState
{
get { return (string)GetValue(Uncheck_MouseOverStateProperty); }
set { SetValue(Uncheck_MouseOverStateProperty, value); }
}
public string Uncheck_PressedState
{
get { return (string)GetValue(Uncheck_PressedStateProperty); }
set { SetValue(Uncheck_PressedStateProperty, value); }
}
public static DependencyProperty Check_NormalStateProperty;
public static DependencyProperty Check_MouseOverStateProperty;
public static DependencyProperty Check_PressedStateProperty;
public static DependencyProperty Uncheck_NormalStateProperty;
public static DependencyProperty Uncheck_MouseOverStateProperty;
public static DependencyProperty Uncheck_PressedStateProperty;
}
}
<Style TargetType="{x:Type local:ImageToggleButton}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:ImageToggleButton}">
<Border>
<Image Name="imgground" Source="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(local:ImageToggleButton.Uncheck_NormalState)}" Stretch="Fill"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter TargetName="imgground" Property="Source" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(local:ImageToggleButton.Check_NormalState)}"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True" >
<Setter TargetName="imgground" Property="Source" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(local:ImageToggleButton.Check_MouseOverState)}"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="imgground" Property="Source" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(local:ImageToggleButton.Check_PressedState)}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>