How to create a custom style for checkbox in WPF?
In this article I am going to explain how to create a custom styling for wpf checkbox. We can modify the checkbox according to our custom requirement. Please check below code for modifying the template & creating custom checkbox in WPF.
<Window.Resources> <Style TargetType="{x:Type CheckBox}" x:Key="customCheckboxStyle"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type CheckBox}"> <StackPanel Orientation="Horizontal"> <Image x:Name="checkboxImage" Source="normal_image.png" Width="32"/> <ContentPresenter/> </StackPanel> <ControlTemplate.Triggers> <Trigger Property="IsChecked" Value="True"> <Setter TargetName="checkboxImage" Property="Source" Value="checked_image.png"/> </Trigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsMouseOver" Value="True"/> <Condition Property="IsChecked" Value="False"/> </MultiTrigger.Conditions> <Setter TargetName="checkboxImage" Property="Source" Value="hover_image.png"/> </MultiTrigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </Window.Resources>
how to get the Value="checked_image.png" through c# code?so that it can be changed dynamically
ReplyDelete