IsSelectionActive and programmatically setting a ListBox selected index

I was having trouble working out why in WPF when setting a ListBox SelectedIndex in code wasn’t showing my item up as selected. Turns out I had code set on Selector.IsSelectionActive.

When we’d set up the look and feel of our ListBox and ListBoxItems we didn’t notice that Blend added the following code on us which is the same as the unselected state. So can either delete that particular trigger or set the appropriate effect.

<MultiTrigger xmlns:Windows=”clr-namespace:System.Windows;assembly=System.Windows”>
    <
MultiTrigger.Conditions>
        <
ConditionProperty=”IsSelected”Value=”true”/>
        <
ConditionProperty=”Selector.IsSelectionActive”Value=”false”/>
    </
MultiTrigger.Conditions>
    <
SetterProperty=”Foreground”Value=”{DynamicResource {x:StaticSystemColors.HighlightTextBrushKey}}”/>
    <
Windows:SetterProperty=”Fill”TargetName=”rectangle”>
        <
Setter.Value>
            <
LinearGradientBrush EndPoint=”0.497,1.21″StartPoint=”0.497,0.584″SpreadMethod=”Repeat”>
                <
GradientStop Color=”#FF7C7C7C”Offset=”0″/>
                <
GradientStop Color=”#FFB3B3B3″Offset=”1″/>
            </
LinearGradientBrush>
        </
Setter.Value>
    </
Windows:Setter>
</
MultiTrigger>

 

Technorati Tags: ,