Note that there are some explanatory texts on larger screens.

plurals
  1. POChanging background of custom WPF ComboBox
    primarykey
    data
    text
    <p>I've got a custom ComboBox which should react to the value of some dependency properties. (e.g. validation). Now, I just can't find out how to change the background of the combobox control in the triggers of the controltemplate... I can change the dropdown menu, but haven't yet found out how to change the background of the whole control. The dependency properties are set correctly, here's the XAML:</p> <pre class="lang-xml prettyprint-override"><code> &lt;ControlTemplate x:Key="ComboBoxToggleButton" TargetType="ToggleButton"&gt; &lt;Grid&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition /&gt; &lt;ColumnDefinition Width="20" /&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Border x:Name="Border" Grid.ColumnSpan="2" CornerRadius="2" Background="{StaticResource NormalBrush}" BorderBrush="{StaticResource NormalBorderBrush}" BorderThickness="1" /&gt; &lt;Border Grid.Column="0" CornerRadius="2,0,0,2" Margin="1" Background="{StaticResource WindowBackgroundBrush}" BorderBrush="{StaticResource NormalBorderBrush}" BorderThickness="0,0,1,0" /&gt; &lt;Path x:Name="Arrow" Grid.Column="1" Fill="{StaticResource GlyphBrush}" HorizontalAlignment="Center" VerticalAlignment="Center" Data="M 0 0 L 4 4 L 8 0 Z"/&gt; &lt;/Grid&gt; &lt;ControlTemplate.Triggers&gt; &lt;Trigger Property="ToggleButton.IsMouseOver" Value="true"&gt; &lt;Setter TargetName="Border" Property="Background" Value="{StaticResource DarkBrush}" /&gt; &lt;/Trigger&gt; &lt;Trigger Property="ToggleButton.IsChecked" Value="true"&gt; &lt;Setter TargetName="Border" Property="Background" Value="{StaticResource PressedBrush}" /&gt; &lt;/Trigger&gt; &lt;Trigger Property="IsEnabled" Value="False"&gt; &lt;Setter TargetName="Border" Property="Background" Value="{StaticResource DisabledBackgroundBrush}" /&gt; &lt;Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DisabledBorderBrush}" /&gt; &lt;Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/&gt; &lt;Setter TargetName="Arrow" Property="Fill" Value="{StaticResource DisabledForegroundBrush}" /&gt; &lt;/Trigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;/ControlTemplate&gt; &lt;ControlTemplate x:Key="ComboBoxTextBox" TargetType="TextBox"&gt; &lt;Border x:Name="PART_ContentHost" Focusable="False" Background="{TemplateBinding Background}" /&gt; &lt;/ControlTemplate&gt; &lt;Style x:Key="{x:Type local:ErgoDentComboBox}" TargetType="ComboBox" BasedOn="ComboBox"&gt; &lt;Setter Property="SnapsToDevicePixels" Value="true"/&gt; &lt;!--&lt;Setter Property="OverridesDefaultStyle" Value="true"/&gt;--&gt; &lt;Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/&gt; &lt;Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/&gt; &lt;Setter Property="ScrollViewer.CanContentScroll" Value="true"/&gt; &lt;Setter Property="MinWidth" Value="120"/&gt; &lt;Setter Property="MinHeight" Value="20"/&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type local:ErgoDentComboBox}"&gt; &lt;Grid&gt; &lt;ToggleButton Name="ToggleButton" Template="{StaticResource ComboBoxToggleButton}" Grid.Column="2" Focusable="false" IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press"&gt; &lt;/ToggleButton&gt; &lt;ContentPresenter Name="ContentSite" IsHitTestVisible="False" Content="{TemplateBinding SelectionBoxItem}" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" Margin="3,3,23,3" VerticalAlignment="Center" HorizontalAlignment="Left" /&gt; &lt;TextBox x:Name="PART_EditableTextBox" Style="{x:Null}" Template="{StaticResource ComboBoxTextBox}" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="3,3,23,3" Focusable="True" Background="Transparent" Visibility="Hidden" IsReadOnly="{TemplateBinding IsReadOnly}"/&gt; &lt;Popup Name="Popup" Placement="Bottom" IsOpen="{TemplateBinding IsDropDownOpen}" AllowsTransparency="True" Focusable="False" PopupAnimation="Slide"&gt; &lt;Grid Name="DropDown" SnapsToDevicePixels="True" MinWidth="{TemplateBinding ActualWidth}" MaxHeight="{TemplateBinding MaxDropDownHeight}"&gt; &lt;Border x:Name="DropDownBorder" Background="{StaticResource WindowBackgroundBrush}" BorderThickness="1" BorderBrush="{StaticResource SolidBorderBrush}"/&gt; &lt;ScrollViewer Margin="4,6,4,6" SnapsToDevicePixels="True"&gt; &lt;StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" /&gt; &lt;/ScrollViewer&gt; &lt;/Grid&gt; &lt;/Popup&gt; &lt;/Grid&gt; &lt;ControlTemplate.Triggers&gt; &lt;Trigger Property="HasItems" Value="false"&gt; &lt;Setter TargetName="DropDownBorder" Property="MinHeight" Value="95"/&gt; &lt;/Trigger&gt; &lt;Trigger Property="IsEnabled" Value="false"&gt; &lt;Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/&gt; &lt;/Trigger&gt; &lt;Trigger Property="IsGrouping" Value="true"&gt; &lt;Setter Property="ScrollViewer.CanContentScroll" Value="false"/&gt; &lt;/Trigger&gt; &lt;Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="true"&gt; &lt;Setter TargetName="DropDownBorder" Property="CornerRadius" Value="4"/&gt; &lt;Setter TargetName="DropDownBorder" Property="Margin" Value="0,2,0,0"/&gt; &lt;/Trigger&gt; &lt;Trigger Property="IsEditable" Value="true"&gt; &lt;Setter Property="IsTabStop" Value="false"/&gt; &lt;Setter TargetName="PART_EditableTextBox" Property="Visibility" Value="Visible"/&gt; &lt;Setter TargetName="ContentSite" Property="Visibility" Value="Hidden"/&gt; &lt;/Trigger&gt; &lt;!-- THIS ISN'T WORKING --&gt; &lt;Trigger Property="IsValidationError" Value="False"&gt; &lt;Setter Property="BorderBrush" Value="DarkGreen" /&gt; &lt;Setter Property="Background" Value="Green" /&gt; &lt;/Trigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;Style.Triggers&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; </code></pre> <p>In the code of the control I can easily set the background, how would I do this in the triggers?</p> <p>Thanks</p> <p>Danny</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload