Created
March 27, 2018 18:03
-
-
Save julesx/12de186b61d27f9bb80f593ba0d7154e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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