Troubleshooting Resources, Styles, and Triggers

If you reference a style in a StaticResource extension and the style is not defined at all in your application, you will get an XamlParseException. However, a XamlParseException can occur in several other scenarios as well. For example, if you define a style twice in your application with the same key identifier, you will get a XamlParseException. The following code shows an example of such a scenario:

<Grid.Resources>
   <Style x:Key="lstStyle" TargetType="ListBox">
     <Setter Property="BorderBrush" Value="Blue"></Setter>
   </Style>
   <Style x:Key="lstStyle" TargetType="ListBox">
     <Setter Property="Background" Value="PaleGreen"></Setter>
   </Style>
<Grid.Resources>

To identify why exactly the exception occurred ...

Get XAML Developer Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.