Quantcast
Channel: Ribbon for WPF - Recent Posts
Viewing all articles
Browse latest Browse all 1458

Re: Not able to change background color of checkcox with CheckBoxKey style.

$
0
0

Hi,

Thanks for quick response.

I was able to pull out the style for checkboxkey. But not able to figure it out to make it work as per my requirement.

Below is the changed style i am using: 

<Style TargetType="CheckBox" BasedOn="{StaticResource {x:Static ribbon:RibbonStyles.CheckBoxKey}}"><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type CheckBox}"><DockPanel Background="Transparent" SnapsToDevicePixels="True"><!-- 1/28/2010 - Set FlowDirection to LeftToRight so check is always drawn left-to-right --><Border x:Name="OuterBorder" DockPanel.Dock="Left" Width="13" Height="13" BorderThickness="1"
								VerticalAlignment="Center"
								BorderBrush="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type editors:PartEditBox},ResourceId=OfficeCheckBoxOuterBorderNormalBrush}}"
								SnapsToDevicePixels="True" FlowDirection="LeftToRight"><Border x:Name="InnerBorder" Margin="1" BorderThickness="1"
									BorderBrush="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type editors:PartEditBox},ResourceId=OfficeCheckBoxInnerBorderNormalBrush}}"
									Background="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type editors:PartEditBox},ResourceId=OfficeCheckBoxInnerBackgroundNormalBrush}}"
									SnapsToDevicePixels="True"><Grid><Path x:Name="CheckBox" Margin="-1" HorizontalAlignment="Center" VerticalAlignment="Center"
											Visibility="Collapsed"
											Fill="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type editors:PartEditBox},ResourceId=OfficeCheckBoxForegroundBrush}}"
											Data="M 0.5,6.5 L 3.5,9.5 L 4.5,9.5 L 7.5,1.5 L 6,0.5 L 3.5,7 L 1.5,5 Z"
											SnapsToDevicePixels="False" /><Rectangle x:Name="Indeterminate" Visibility="Collapsed" Opacity="0.5"
											Fill="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type editors:PartEditBox},ResourceId=OfficeCheckBoxForegroundBrush}}" /></Grid></Border></Border><Grid HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
								VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="True"><ContentPresenter x:Name="contentPresenter" Margin="{TemplateBinding Padding}"
									SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
									ContentTemplate="{TemplateBinding ContentTemplate}" RecognizesAccessKey="True"
									Content="{TemplateBinding Content}" /></Grid></DockPanel><ControlTemplate.Triggers><Trigger Property="HasContent" Value="true"><Setter Property="FocusVisualStyle" Value="{StaticResource CheckRadioFocusVisual}" /><Setter Property="Padding" Value="2,0,0,0" /></Trigger><Trigger Property="IsChecked" Value="True"><Setter TargetName="CheckBox" Property="Visibility" Value="Visible" /></Trigger><Trigger Property="IsChecked" Value="{x:Null}"><Setter TargetName="Indeterminate" Property="Visibility" Value="Visible" /></Trigger><MultiTrigger><MultiTrigger.Conditions><Condition Property="IsEnabled" Value="True" /><Condition Property="IsMouseOver" Value="True" /></MultiTrigger.Conditions><Setter TargetName="OuterBorder" Property="BorderBrush"
									Value="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type editors:PartEditBox},ResourceId=OfficeCheckBoxOuterBorderHoverBrush}}" /><Setter TargetName="OuterBorder" Property="Background"
									Value="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type editors:PartEditBox},ResourceId=OfficeCheckBoxOuterBackgroundHoverBrush}}" /><Setter TargetName="InnerBorder" Property="BorderBrush"
									Value="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type editors:PartEditBox},ResourceId=OfficeCheckBoxInnerBorderHoverBrush}}" /><Setter TargetName="InnerBorder" Property="Background"
									Value="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type editors:PartEditBox},ResourceId=OfficeCheckBoxInnerBackgroundHoverBrush}}" /></MultiTrigger><MultiTrigger><MultiTrigger.Conditions><Condition Property="IsEnabled" Value="True" /><Condition Property="IsKeyboardFocused" Value="True" /></MultiTrigger.Conditions><Setter TargetName="OuterBorder" Property="BorderBrush"
									Value="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type editors:PartEditBox},ResourceId=OfficeCheckBoxOuterBorderHoverBrush}}" /><Setter TargetName="OuterBorder" Property="Background"
									Value="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type editors:PartEditBox},ResourceId=OfficeCheckBoxOuterBackgroundHoverBrush}}" /><Setter TargetName="InnerBorder" Property="BorderBrush"
									Value="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type editors:PartEditBox},ResourceId=OfficeCheckBoxInnerBorderHoverBrush}}" /><Setter TargetName="InnerBorder" Property="Background"
									Value="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type editors:PartEditBox},ResourceId=OfficeCheckBoxInnerBackgroundHoverBrush}}" /></MultiTrigger><MultiTrigger><MultiTrigger.Conditions><Condition Property="IsEnabled" Value="True" /><Condition Property="IsPressed" Value="True" /></MultiTrigger.Conditions><Setter TargetName="OuterBorder" Property="BorderBrush"
									Value="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type editors:PartEditBox},ResourceId=OfficeCheckBoxOuterBorderPressedBrush}}" /><Setter TargetName="OuterBorder" Property="Background"
									Value="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type editors:PartEditBox},ResourceId=OfficeCheckBoxOuterBackgroundPressedBrush}}" /><Setter TargetName="InnerBorder" Property="BorderBrush"
									Value="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type editors:PartEditBox},ResourceId=OfficeCheckBoxInnerBorderPressedBrush}}" /><Setter TargetName="InnerBorder" Property="Background"
									Value="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type editors:PartEditBox},ResourceId=OfficeCheckBoxInnerBackgroundPressedBrush}}" /></MultiTrigger><Trigger Property="IsEnabled" Value="False"><Setter TargetName="OuterBorder" Property="BorderBrush"
									Value="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type editors:PartEditBox},ResourceId=OfficeCheckBoxOuterBorderDisabledBrush}}" /><Setter TargetName="OuterBorder" Property="Background"
									Value="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type editors:PartEditBox},ResourceId=OfficeCheckBoxOuterBackgroundDisabledBrush}}" /><Setter TargetName="InnerBorder" Property="BorderBrush"
									Value="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type editors:PartEditBox},ResourceId=OfficeCheckBoxInnerBorderDisabledBrush}}" /><Setter TargetName="InnerBorder" Property="Background"
									Value="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type editors:PartEditBox},ResourceId=OfficeCheckBoxInnerBackgroundDisabledBrush}}" /><!--<Setter Property="Foreground"
									Value="{DynamicResource {x:Static editorsThemes:EditorsCommonDictionary.ButtonForegroundDisabledBrushKey}}" />--></Trigger><DataTrigger Binding="{Binding IsUpdated}" Value="True"><Setter Property="Background" Value="Yellow"/></DataTrigger></ControlTemplate.Triggers></ControlTemplate></Setter.Value></Setter><Setter Property="FontFamily" Value="{StaticResource NMXFontFamily}"/><Setter Property="FontSize" Value="11" /><Setter Property="Foreground" Value="Black" /><Setter Property="AutomationProperties.AutomationId" 
                Value="{Binding RelativeSource={RelativeSource Self}, Path=Content, TargetNullValue={x:Static sys:String.Empty}}" /></Style>

 But after this change my checkbox are not visible. I can check / uncheck them but they are not visible or displayed properly. They become transparent.

 

My actual requriement is, I want to run this trigger on checkboxes:

<DataTrigger Binding="{Binding IsUpdated}" Value="True"><Setter Property="Background" Value="Yellow"/></DataTrigger>

 So that background of checkbox will get change accordingly.

 

Please suggest me how i can make it work.

 

Thanks,
Piyush


Viewing all articles
Browse latest Browse all 1458

Trending Articles