WPF MultiSelect MVVM

 xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
        xmlns:ii="http://schemas.microsoft.com/expression/2010/interactivity"

  <i:Interaction.Triggers>
                <i:EventTrigger EventName="SelectionChanged">
                    <i:InvokeCommandAction Command="{Binding SelectedItemsCmd}" CommandParameter="{Binding Path=SelectedItems,ElementName=dg}"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
private ICommand selectedItemsCmd;
        public ICommand SelectedItemsCmd
        {
            get
            {
                if(selectedItemsCmd==null)
                {
                    selectedItemsCmd = new DelegateCommand(SelectedItemsCmdExecuted);
                }
                return selectedItemsCmd;
            }
        }

        private void SelectedItemsCmdExecuted(object obj)
        {
            System.Collections.IList items = (System.Collections.IList)obj;
            if(items!=null && items.Count>0)
            {
                var collection = items.Cast<SalesOrderDetail>();
                SelectedOrders = new ObservableCollection<SalesOrderDetail>(collection);
            }                        
        }

 

posted @ 2020-12-02 17:13  FredGrit  阅读(105)  评论(0编辑  收藏  举报