Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Modify the ListBox.ItemTemplate to use a checkbox, and bind the CheckBox.IsChecked to SubSystem.IsSelected and CheckBox.Content to SubSystem.Name:</p> <p>XAML:</p> <pre><code>&lt;ListBox ItemsSource="{Binding}"&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;CheckBox IsChecked="{Binding IsSelected}" Content="{Binding Name}" Margin="5" Focusable="False" /&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; </code></pre> <p>C#:</p> <pre><code>private void window1_Loaded(object sender, RoutedEventArgs e) { this.SubSystems = new List&lt;SubSystem&gt;(); this.SubSystems.Add(new SubSystem() { Name = "SubSystem 1", IsSelected = false }); this.SubSystems.Add(new SubSystem() { Name = "SubSystem 2", IsSelected = false }); this.SubSystems.Add(new SubSystem() { Name = "SubSystem 3", IsSelected = true }); this.SubSystems.Add(new SubSystem() { Name = "SubSystem 4", IsSelected = false }); this.SubSystems.Add(new SubSystem() { Name = "SubSystem 5", IsSelected = true }); this.DataContext = this.SubSystems; } </code></pre> <p>And make sure you set Focusable="False" to the CheckBoxes or else your users will be able to tab into them.</p> <p><strong>EDIT:</strong></p> <p>Also from what you added you might be missing the ElementName property (if SubSystems is NOT the DataContext of your window, you need to specify where the SubSystems property is coming from with the ElementName binding property):</p> <pre><code> &lt;ListBox ItemTemplate="{StaticResource checkBox}" ItemsSource="{Binding ElementName=window1, Path=SubSystems}" /&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