How to Conditional Format Checkboxes? #4484
Unanswered
BrennanCarte
asked this question in
Q&A
Replies: 1 comment
-
@BrennanCarte You can use the CheckBoxHelper to set several brushes. Sample: 2024-06-25_16h53_48.mp4<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Page.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml"/>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml"/>
<!-- Theme setting -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/Light.Blue.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Page.Resources>
<Grid>
<StackPanel HorizontalAlignment="Center" Orientation="Vertical">
<CheckBox x:Name="ConditionalFormatting" Margin="2" Content="Click me...">
</CheckBox>
<CheckBox Margin="2" Content="Click and me...">
<CheckBox.Style>
<Style BasedOn="{StaticResource MahApps.Styles.CheckBox}" TargetType="CheckBox">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=ConditionalFormatting, Path=IsChecked}" Value="true">
<Setter Property="mah:CheckBoxHelper.BackgroundChecked" Value="SlateBlue"/>
<Setter Property="mah:CheckBoxHelper.BackgroundCheckedDisabled" Value="SlateBlue"/>
<Setter Property="mah:CheckBoxHelper.BackgroundCheckedMouseOver" Value="SlateBlue"/>
<Setter Property="mah:CheckBoxHelper.BackgroundCheckedPressed" Value="SlateBlue"/>
<Setter Property="mah:CheckBoxHelper.ForegroundChecked" Value="White"/>
<Setter Property="mah:CheckBoxHelper.ForegroundCheckedDisabled" Value="White"/>
<Setter Property="mah:CheckBoxHelper.ForegroundCheckedMouseOver" Value="White"/>
<Setter Property="mah:CheckBoxHelper.ForegroundCheckedPressed" Value="White"/>
<Setter Property="mah:CheckBoxHelper.BackgroundIndeterminate" Value="{DynamicResource MahApps.Brushes.CheckBox.BackgroundIndeterminate}"/>
<Setter Property="mah:CheckBoxHelper.BackgroundIndeterminateDisabled" Value="{DynamicResource MahApps.Brushes.CheckBox.BackgroundIndeterminateDisabled}"/>
<Setter Property="mah:CheckBoxHelper.BackgroundIndeterminateMouseOver" Value="{DynamicResource MahApps.Brushes.CheckBox.BackgroundIndeterminateMouseOver}"/>
<Setter Property="mah:CheckBoxHelper.BackgroundIndeterminatePressed" Value="{DynamicResource MahApps.Brushes.CheckBox.BackgroundIndeterminatePressed}"/>
<Setter Property="mah:CheckBoxHelper.BackgroundUnchecked" Value="PaleVioletRed"/>
<Setter Property="mah:CheckBoxHelper.BackgroundUncheckedDisabled" Value="PaleVioletRed"/>
<Setter Property="mah:CheckBoxHelper.BackgroundUncheckedMouseOver" Value="PaleVioletRed"/>
<Setter Property="mah:CheckBoxHelper.BackgroundUncheckedPressed" Value="PaleVioletRed"/>
<Setter Property="ToolTip" Value="A bad thing is happening, user needs to pay attention."/>
</DataTrigger>
<!--Further DataTriggers Here-->
</Style.Triggers>
</Style>
</CheckBox.Style>
</CheckBox>
</StackPanel>
</Grid>
</Page> |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First time poster here. I'm working on an application that requires me to do conditional formatting on a bunch of elements. While I've had no problems with most elements, checkboxes elude me. I've got this general code structure below going pretty much everywhere:
This works on everything except checkboxes. The tooltip shows up, but I'm unable to get the coloring I want. I've read through Controls.CheckBox.xaml and I'm pretty certain the reason this isn't working is due to checkboxes all using MahApps brushes, but I can't figure out the correct way to override them. Can anyone point me in the right direction?
Beta Was this translation helpful? Give feedback.
All reactions