How to support ListBox SelectedItems binding with MVVM in a navigable application

前端 未结 9 1222
有刺的猬
有刺的猬 2020-11-27 15:06

I am making a WPF application that is navigable via custom \"Next\" and \"Back\" buttons and commands (i.e. not using a NavigationWindow). On one screen, I have

9条回答
  •  借酒劲吻你
    2020-11-27 15:54

    This was pretty easy to do with a Command and the Interactivities EventTrigger. ItemsCount is just a bound property to use on your XAML, should you want to display the updated count.

    XAML:

         
            
             
                
             
                
        
    
    

    ViewModel:

        private int _itemsCount;
        private RelayCommand _selectionChangedCommand;
    
        public ICommand SelectionChangedCommand
        {
           get {
                    return _selectionChangedCommand ?? (_selectionChangedCommand = 
                 new RelayCommand((itemsCount) => { ItemsCount = itemsCount; }));
               }
        }
    
            public int ItemsCount
            {
                get { return _itemsCount; }
                set { 
                  _itemsCount = value;
                  OnPropertyChanged("ItemsCount");
                 }
            }
    

提交回复
热议问题