I have created a ComboBoxStyle.
=> When I apply this to the combo boxes and UI becomes unstable with the below error.
<Setter Property="Foreground" Value="{StaticResource OutsideFontBrush}"/>
I get below error -
Error 11 '{DependencyProperty.UnsetValue}' is not a valid value for the 'System.Windows.Documents.TextElement.Foreground' property on a Setter.
Note : OutsideFontBrush Resource exists. I have made sure that all the resources used in this style exist.
=> I tried changing the StaticResource to DynamicResource. But it doesnt fix it.
=> When I try to harcode the Foreground property to "Black". I get "Object reference not set to an object" error.
<Setter Property="Foreground" Value="Black"/>
Not sure how to fix this. Any Ideas ?
Below is the style =>
<Style x:Key="ComboBoxStyle" TargetType="{x:Type ComboBox}" BasedOn="{StaticResource ErrorTemplateStyle}"><Setter Property="SnapsToDevicePixels" Value="true"/><Setter Property="Foreground" Value="{StaticResource OutsideFontBrush}"/><Setter Property="FontWeight" Value="Normal"/><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type ComboBox}"><ControlTemplate.Resources><Storyboard x:Key="FocusedOn"><DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="FocusVisualElement" Storyboard.TargetProperty="(UIElement.Opacity)"><SplineDoubleKeyFrame KeyTime="00:00:00.1000000" Value="1"/></DoubleAnimationUsingKeyFrames></Storyboard><Storyboard x:Key="FocusedOff"><DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="FocusVisualElement" Storyboard.TargetProperty="(UIElement.Opacity)"><SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="0"/></DoubleAnimationUsingKeyFrames></Storyboard></ControlTemplate.Resources><Grid Background="{commonMarkup:ColorExtension Color={StaticResource ControlBackgroundColor}}"><ContentPresenter HorizontalAlignment="Left" Margin="3,3,23,3" x:Name="ContentSite" VerticalAlignment="Center" Content="{TemplateBinding SelectionBoxItem}" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" IsHitTestVisible="True"/><ToggleButton Template="{DynamicResource ComboBoxToggleButton}" x:Name="ToggleButton" Focusable="false" IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press"/><TextBox Visibility="Hidden" Template="{DynamicResource ComboBoxTextBox}" HorizontalAlignment="Left" Margin="3,3,23,3" x:Name="PART_EditableTextBox" Style="{x:Null}" VerticalAlignment="Center" Focusable="True" Background="Transparent" IsReadOnly="{TemplateBinding IsReadOnly}"/><Rectangle x:Name="DisabledVisualElement" Fill="{commonMarkup:ColorExtension Color={StaticResource DisabledVisualEmtColor}}" Opacity="0.25" RadiusX="4" RadiusY="4" IsHitTestVisible="True" Visibility="Collapsed" /><Rectangle x:Name="FocusVisualElement" Margin="-1" Stroke="{StaticResource SelectedStrokeBrush}" StrokeThickness="1" RadiusX="4" RadiusY="4" IsHitTestVisible="True" Opacity="0"/><Popup IsOpen="{TemplateBinding IsDropDownOpen}" Placement="Bottom" x:Name="Popup" Focusable="False" AllowsTransparency="False" PopupAnimation="Slide"><Grid MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{TemplateBinding ActualWidth}" x:Name="DropDown" SnapsToDevicePixels="True"><Border x:Name="DropDownBorder" Background="{commonMarkup:ColorExtension Color={StaticResource ControlBackgroundColor}}" BorderBrush="{StaticResource TextBoxNorm}" BorderThickness="1" CornerRadius="1,1,1,1"><ScrollViewer Margin="4,6,4,6" SnapsToDevicePixels="True" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" CanContentScroll="True"><ItemsPresenter KeyboardNavigation.DirectionalNavigation="Contained"/></ScrollViewer></Border></Grid></Popup></Grid><ControlTemplate.Triggers><Trigger Property="IsFocused" Value="True"><Trigger.ExitActions><BeginStoryboard Storyboard="{StaticResource FocusedOff}" x:Name="FocusedOff_BeginStoryboard"/></Trigger.ExitActions><Trigger.EnterActions><BeginStoryboard Storyboard="{StaticResource FocusedOn}"/></Trigger.EnterActions></Trigger><Trigger Property="HasItems" Value="false"><Setter Property="MinHeight" Value="95" TargetName="DropDownBorder"/></Trigger><Trigger Property="IsEnabled" Value="false"><Setter Property="Foreground" Value="{DynamicResource DisabledForeColorBrush}"/><Setter Property="Visibility" TargetName="DisabledVisualElement" Value="Visible"/></Trigger><Trigger Property="IsGrouping" Value="true"><Setter Property="ScrollViewer.CanContentScroll" Value="false"/></Trigger><Trigger Property="AllowsTransparency" SourceName="Popup" Value="true"><Setter Property="CornerRadius" Value="1" TargetName="DropDownBorder"/><Setter Property="Margin" Value="0,2,0,0" TargetName="DropDownBorder"/></Trigger><Trigger Property="IsEditable" Value="true"><Setter Property="IsTabStop" Value="false"/><Setter Property="Visibility" Value="Visible" TargetName="PART_EditableTextBox"/><Setter Property="Visibility" Value="Hidden" TargetName="ContentSite"/></Trigger></ControlTemplate.Triggers></ControlTemplate></Setter.Value></Setter></Style>
Ashish Dhyani