0

I've got a common ResourceDictionary that use an Microsoft example for use a black ComboBox Microsoft Exemple

In execution a exception was thrown : Exception: Cannot find resource named 'NormalBorderBrush'. Resource names are case sensitive.

I just want to declare this combobox in my common ResourceDictionary xaml file

<!-- Combo box--> <ControlTemplate x:Key="ComboBoxToggleButton" TargetType="ToggleButton"> <Border x:Name="Border" Grid.ColumnSpan="2" CornerRadius="2" ... BorderBrush="{StaticResource NormalBorderBrush}" BorderThickness="1" /> ... <!-- Border Brushes --> <LinearGradientBrush x:Key="NormalBorderBrush" StartPoint="0,0" EndPoint="0,1"> <GradientBrush.GradientStops> <GradientStopCollection> <GradientStop Color="#CCC" Offset="0.0"/> <GradientStop Color="#444" Offset="1.0"/> </GradientStopCollection> </GradientBrush.GradientStops> </LinearGradientBrush> 

The NormalBorderBrush is declared in this same file ! What Am I doing wrong ?

Thanks in advance. Eric

3
  • Make sure to declare the Brush before you use it. Maybe just move the Brushdeclaration above the ComboBox Commented Oct 15, 2020 at 12:49
  • Have you added ResourceDictionary.xaml file in in App.Xaml ?? Commented Oct 15, 2020 at 13:02
  • How did you declare NormalBorderBrush ? Show the code for that part also. Commented Oct 15, 2020 at 13:02

1 Answer 1

2

The order in which you define the resources matters.

The XAML compiler processes the file from top to bottom so to be able to reference NormalBorderBrush in the ControlTemplate, you need to define the brush before you define the template:

 <LinearGradientBrush x:Key="NormalBorderBrush" ... /> <ControlTemplate x:Key="ComboBoxToggleButton" ... /> 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.