Cryptic message when trying to apply a style to a Window

<Style x:Key="TriggerWindowStyle" TargetType="{x:Type Window}">

<Style.Triggers>

<Trigger Property="Window.Tag" Value="TurnRed">

<Setter Property = "Background" Value="Red"/>

</Trigger>

</Style.Triggers>

</Style>

Error 2 The Key attribute can only be used on a tag contained in a Dictionary (such as a ResourceDictionary). Line 17 Position 12.

Guess I am stupid because it was not obvious to me that I had to include the style within the context of a resource. Eg.

<Window.Resources>

<!-- Style stuff here -->

</Window.Resources>

Maybe that is why it says "(such as a ResourceDictionary)"

The formal terminology "Dictionary" didn't make it clear what needed to happen.




Answer this question

Cryptic message when trying to apply a style to a Window