Note that there are some explanatory texts on larger screens.

plurals
  1. POGrouped ListBox and SelectionChanged
    primarykey
    data
    text
    <p>I am new in WPF... :)</p> <p>I need ListBox to display grouped items, what works well.</p> <pre><code> &lt;ListBox Width="120" Loaded="ListBox_Loaded" SelectionChanged="ListBox_SelectionChanged" &gt; &lt;ListBox.GroupStyle&gt; &lt;GroupStyle /&gt; &lt;/ListBox.GroupStyle&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;ListBox ItemsSource="{Binding Items}" BorderThickness="0" /&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; </code></pre> <p>But in the *ListBox_SelectionChanged* SelectedIndex is still -1 and also SelectedItems collection is empty.</p> <p>Here is piece of code behind:</p> <pre><code> public ICollectionView Groups() { List&lt;Groups&gt; groups = new List&lt;AC.Groups&gt;(); groups.Add(new AC.Groups { Items = Properties.Settings.Default.Worker, Name="Worker" }); groups.Add(new AC.Groups { Items = Properties.Settings.Default.Flow, Name = "Flow" }); ICollectionView groups = CollectionViewSource.GetDefaultView(groups); groups.GroupDescriptions.Add(new PropertyGroupDescription("Name")); return groups; } private void ListBox_Loaded(object sender, RoutedEventArgs e) { (sender as ListBox).ItemsSource = Groups(); } private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { MessageBox.Show((sender as ListBox).SelectedIndex.ToString()); } class Groups { public System.Collections.Specialized.StringCollection Items { get; set; } public string Name { get; set; } public override string ToString() { return Name; } } </code></pre> <p>Thank you for help!</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.
 

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