Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Something in your code must be causing this issues. Below is a sample which behaves as expected. </p> <p>XAML:</p> <pre><code>&lt;Window x:Class="TestDemo.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"&gt; &lt;Window.Resources&gt; &lt;RoutedUICommand x:Key="EditItemsCommand" Text="Edit Items" /&gt; &lt;/Window.Resources&gt; &lt;Window.CommandBindings&gt; &lt;CommandBinding Command="{StaticResource EditItemsCommand}" CanExecute="EditItems_CanExecute" Executed="EditItems_Executed" /&gt; &lt;/Window.CommandBindings&gt; &lt;StackPanel&gt; &lt;Button Name="_editButton" Content="Edit" Command="{StaticResource EditItemsCommand}" /&gt; &lt;Button Content="Unselect all" Click="OnUnselectAll" /&gt; &lt;ListView Name="_listView" ItemsSource="{Binding Path=Items}" SelectionMode="Extended" MouseDoubleClick="OnListViewMouseDoubleClick"&gt; &lt;/ListView&gt; &lt;/StackPanel&gt; &lt;/Window&gt; </code></pre> <p>Code behind:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Windows; using System.Windows.Input; namespace TestDemo { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); DataContext = this; } public IEnumerable&lt;string&gt; Items { get { for (int i = 0; i &lt; 10; i++) { yield return i.ToString(); } } } private void EditItems_CanExecute(object sender, CanExecuteRoutedEventArgs e) { e.CanExecute = _listView != null &amp;&amp; _listView.SelectedItems.Count &gt; 0; } private void EditItems_Executed(object sender, ExecutedRoutedEventArgs e) { EditWindow editWindow = new EditWindow(); editWindow.EditItems = _listView.SelectedItems.Cast&lt;string&gt;(); editWindow.ShowDialog(); } private void OnListViewMouseDoubleClick(object sender, MouseButtonEventArgs e) { _editButton.Command.Execute(null); } private void OnUnselectAll(object sender, RoutedEventArgs e) { _listView.SelectedItem = null; } } } </code></pre> <p>XAML:</p> <pre><code>&lt;Window x:Class="TestDemo.EditWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="EditWindow"&gt; &lt;ListBox ItemsSource="{Binding Path=EditItems}" /&gt; &lt;/Window&gt; </code></pre> <p>Code behind:</p> <pre><code>using System; using System.Collections.Generic; using System.Windows; namespace TestDemo { public partial class EditWindow : Window { public EditWindow() { InitializeComponent(); DataContext = this; } public IEnumerable&lt;string&gt; EditItems { get; set; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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