Skip to content

Instantly share code, notes, and snippets.

@julesx
Created March 27, 2018 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julesx/12de186b61d27f9bb80f593ba0d7154e to your computer and use it in GitHub Desktop.
Save julesx/12de186b61d27f9bb80f593ba0d7154e to your computer and use it in GitHub Desktop.
<CheckBox x:Class="WpfApp1.ImageCheckBox"
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"
xmlns:local="clr-namespace:WpfApp1"
Name="RootCheckBox"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<CheckBox.Template>
<ControlTemplate TargetType="{x:Type CheckBox}">
<DockPanel>
<CheckBox x:Name="Foo" IsChecked="{Binding IsChecked, RelativeSource={RelativeSource TemplatedParent}}" />
</DockPanel>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter TargetName="Foo" Property="Background" Value="{Binding CustomColor, ElementName=RootCheckBox}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</CheckBox.Template>
</CheckBox>
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace WpfApp1
{
/// <summary>
/// Interaction logic for ImageCheckBox.xaml
/// </summary>
public partial class ImageCheckBox
{
public ImageCheckBox()
{
InitializeComponent();
}
public SolidColorBrush CustomColor
{
get { return (SolidColorBrush)GetValue(CustomColorProperty); }
set { SetValue(CustomColorProperty, value); }
}
// Using a DependencyProperty as the backing store for CustomColor. This enables animation, styling, binding, etc...
public static readonly DependencyProperty CustomColorProperty =
DependencyProperty.Register("CustomColor", typeof(SolidColorBrush), typeof(ImageCheckBox));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment