0

The following code throws the exception "System.NullReferenceException was unhandled Message=Object reference not set to an instance of an object. Source=Wizbang":

<ListBox.ItemContainerStyle>
    <Style TargetType="{x:Type ListBoxItem}">
        <Style.Resources>
            <SolidColorBrush x:Key="SCB" Color="Orange" />
        </Style.Resources>
        <Style.Triggers>
            <Trigger Property="IsSelected" Value="True" >
                <Setter Property="Background" Value="{StaticResource SCB}" />
            </Trigger>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Background" Value="Orange" />
            </Trigger>
        </Style.Triggers>
    </Style>
</ListBox.ItemContainerStyle>

However, if I remove the StaticResource reference in the first Trigger's Setter, and replace it with string value, such as, "Orange", like in the second Trigger, everything works fine.

I cannot figure out why. I use StaticResources similarly in Triggers elsewhere, but it seems that since this is a ListBox.ItemContainerStyle, something works differently.

4

0 回答 0