Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are a few ways to do this but I'll walk you through one of the the simplest (but not the purest from an architectural perspective).</p> <p>Basically you want to find out when the selection of the ListBox changes. The ListBox raises a SelectionChanged event which can be listened to in the code behind. </p> <pre><code> &lt;ListBox x:Name="List1" ItemsSource="{Binding}" SelectionChanged="SelectionChangedHandler" SelectionMode="Single" &gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;TextBlock Text="{Binding}" FontSize="20"/&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; </code></pre> <p>Then have a handler something like:</p> <pre><code>private void SelectionChangedHandler(object sender, SelectionChangedEventArgs e) { IList selectedItems = e.AddedItems; string val = selectedItems.OfType&lt;string&gt;().FirstOrDefault(); NavigationService.Navigate(new Uri(val)); } </code></pre> <p>One thing you'll need to be aware of is that ListBoxes support multiple selection. For this reason, the event arguments give you back a list of the selected items. For simplicity, all I've done is taken the first value from this list and used that as the navigation value. Notice how I've also set the SlectionMode property of the ListBox to Single which will ensure the user can only select one item.</p> <p>If I were doing this for real I'd look into creating an TriggerAction tat can be hooked up to an event trigger through xaml which will remove the for code behinds. Take a look at <a href="https://stackoverflow.com/questions/3142953/in-silverlight-how-to-bind-listbox-item-selection-to-a-navigate-event">this link</a> if you're interesetd.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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