Note that there are some explanatory texts on larger screens.

plurals
  1. POListBox expand selected item
    text
    copied!<p>I have the following code snippet (copy and paste into kaxaml, xamlpad, etc to try it) that collapses all but the selected item. However, I want to revert back to all visible when the mouse is not over the <code>ListBox</code> and I just cannot get it to work short of going code behind. I am using the <code>IsMouseOver</code> ListBox property to set selected item properties on the <code>ListBox</code> to attempt to trigger an update but no luck. Any ideas?</p> <p><pre></p> <code>&lt;Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt; &lt;Grid&gt; &lt;ListBox Name="lb" Width="100" Height="100" Background="Red" SelectionMode="Single"&gt; &lt;ListBox.ItemsPanel&gt; &lt;ItemsPanelTemplate&gt; &lt;UniformGrid Columns="1"/&gt; &lt;/ItemsPanelTemplate&gt; &lt;/ListBox.ItemsPanel&gt; &lt;ListBoxItem Background="AliceBlue"&gt;Item 1 &lt;/ListBoxItem&gt; &lt;ListBoxItem Background="Aquamarine"&gt;Item &lt;/ListBoxItem&gt; &lt;ListBoxItem Background="Azure"&gt;Item &lt;/ListBoxItem&gt; &lt;ListBox.ItemContainerStyle&gt; &lt;Style TargetType="{x:Type ListBoxItem}"&gt; &lt;Setter Property="Visibility" Value="Visible"/&gt; &lt;Style.Triggers&gt; &lt;MultiDataTrigger&gt; &lt;MultiDataTrigger.Conditions&gt; &lt;Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsSelected}" Value="False"/&gt; &lt;Condition Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBox}},Path=SelectedItems.Count}" Value="1"/&gt; &lt;/MultiDataTrigger.Conditions&gt; &lt;MultiDataTrigger.EnterActions&gt; &lt;BeginStoryboard&gt; &lt;Storyboard Duration="0:0:1"&gt; &lt;ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility"&gt; &lt;DiscreteObjectKeyFrame KeyTime="0:0:1" Value="{x:Static Visibility.Collapsed}"/&gt; &lt;/ObjectAnimationUsingKeyFrames&gt; &lt;DoubleAnimation Duration="0:0:1" Storyboard.TargetProperty="Opacity" To="0"/&gt; &lt;/Storyboard&gt; &lt;/BeginStoryboard&gt; &lt;/MultiDataTrigger.EnterActions&gt; &lt;/MultiDataTrigger&gt; &lt;MultiDataTrigger&gt; &lt;MultiDataTrigger.Conditions&gt; &lt;Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsSelected}" Value="True"/&gt; &lt;Condition Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBox}},Path=SelectedItems.Count}" Value="1"/&gt; &lt;/MultiDataTrigger.Conditions&gt; &lt;MultiDataTrigger.EnterActions&gt; &lt;BeginStoryboard&gt; &lt;Storyboard Duration="0:0:0"&gt; &lt;ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility"&gt; &lt;DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Visibility.Visible}"/&gt; &lt;/ObjectAnimationUsingKeyFrames&gt; &lt;DoubleAnimation Duration="0:0:0" Storyboard.TargetProperty="Opacity" To="1"/&gt; &lt;/Storyboard&gt; &lt;/BeginStoryboard&gt; &lt;/MultiDataTrigger.EnterActions&gt; &lt;/MultiDataTrigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;/ListBox.ItemContainerStyle&gt; &lt;ListBox.Style&gt; &lt;Style&gt; &lt;Style.Triggers&gt; &lt;Trigger Property="ListBox.IsMouseOver" Value="False"&gt; &lt;Setter Property="ListBox.SelectedItem" Value="{x:Null}"/&gt; &lt;Setter Property="ListBoxItem.IsSelected" Value="False"/&gt; &lt;Setter Property="ListBox.SelectedIndex" Value="-1"/&gt; &lt;/Trigger&gt; &lt;EventTrigger RoutedEvent="Mouse.MouseLeave"&gt; &lt;BeginStoryboard&gt; &lt;Storyboard&gt; &lt;Int32Animation Duration="0:0:0" Storyboard.TargetProperty="SelectedIndex" To="-1"/&gt; &lt;/Storyboard&gt; &lt;/BeginStoryboard&gt; &lt;/EventTrigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;/ListBox.Style&gt; &lt;/ListBox&gt; &lt;/Grid&gt; &lt;/Page&gt; </code></pre> <p></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload