Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can wrap those two lists in a <code>ListBox</code> as items, so that when one allergy is selected the corresponding main list is selected as well, that way you can bind to a path of selections, i.e. <code>SelectedMainList -&gt; SelectedAllergy</code>. Not sure how this translates into your specific application code but here is a working example of the scenario, note the Style that is necessary to auto-select the parent list. The example consists of two lists and a TextBlock which displays the chosen item.</p> <pre><code>&lt;TextBlock Text="{Binding ElementName=TestLB, Path=SelectedItem.Content.SelectedItem.Content}"/&gt; &lt;ListBox Name="TestLB"&gt; &lt;ListBox.Resources&gt; &lt;Style TargetType="ListBoxItem"&gt; &lt;Style.Triggers&gt; &lt;Trigger Property="IsKeyboardFocusWithin" Value="True"&gt; &lt;Setter Property="IsSelected" Value="True"/&gt; &lt;/Trigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;/ListBox.Resources&gt; &lt;ListBox.ItemsPanel&gt; &lt;ItemsPanelTemplate&gt; &lt;VirtualizingStackPanel Orientation="Horizontal"/&gt; &lt;/ItemsPanelTemplate&gt; &lt;/ListBox.ItemsPanel&gt; &lt;ListBoxItem&gt; &lt;ListBox&gt; &lt;ListBoxItem&gt;List1-Item1&lt;/ListBoxItem&gt; &lt;ListBoxItem&gt;List1-Item2&lt;/ListBoxItem&gt; &lt;ListBoxItem&gt;List1-Item3&lt;/ListBoxItem&gt; &lt;/ListBox&gt; &lt;/ListBoxItem&gt; &lt;ListBoxItem&gt; &lt;ListBox&gt; &lt;ListBoxItem&gt;List2-Item1&lt;/ListBoxItem&gt; &lt;ListBoxItem&gt;List2-Item2&lt;/ListBoxItem&gt; &lt;ListBoxItem&gt;List2-Item3&lt;/ListBoxItem&gt; &lt;/ListBox&gt; &lt;/ListBoxItem&gt; &lt;/ListBox&gt; </code></pre> <p>You might want to mask the selection of the two main lists, <a href="https://stackoverflow.com/questions/1398559/there-aint-listbox-selectionmode-none-is-there-another-way-to-disable-selecti/1398625#1398625">this answer</a> should help with that.</p> <hr> <p><strong>Edit:</strong> Since the trigger in the above style will also unselect the main list when the keyboard focus is moved away from inside the list you might want to change it to only act when the trigger is fired, this can be done with a single frame animation in the <code>EnterActions</code> of the trigger.</p> <pre><code>&lt;Style TargetType="ListBoxItem"&gt; &lt;Style.Triggers&gt; &lt;Trigger Property="IsKeyboardFocusWithin" Value="True"&gt; &lt;Trigger.EnterActions&gt; &lt;BeginStoryboard&gt; &lt;Storyboard&gt; &lt;BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="IsSelected"&gt; &lt;DiscreteBooleanKeyFrame KeyTime="0:0:0.0" Value="True"/&gt; &lt;/BooleanAnimationUsingKeyFrames&gt; &lt;/Storyboard&gt; &lt;/BeginStoryboard&gt; &lt;/Trigger.EnterActions&gt; &lt;/Trigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; </code></pre>
 

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