Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone!
I'm a newbie so excuse my question if it's too fade or if it's out of place.
any way, In my UI (WPF), i have a ListView that i created containing an observable collection of Type " var Collection = new ObservableCollection<type>" and i have two Buttons "Add" & "Delete" I want to do this:
1- Whenever i select an item from my ListView in the UI(just click on it) , and click the "Add" button, the item is stored in a List called Scenario (var Scenario = new List<type>).
2- Whenever i click the "Delete" button the Scenario list becomes empty.

Any help would be very much appreciated and thank you in advance.

What I have tried:

This is the code in the MainWindowModel, basicly my problem is with
OnSelectChanged()
how can i add the type to the list when it's selected and the button "Add" is pressed?? and is it legitimate to put this logic in
OnSelectChanged()


private Type _newType;
     private bool _isSelected;
     public bool IsSelected
     {
         get { return _isSelected; }
         set
         {
             if (_isSelected != value)
             {
                 _isSelected = value;
                 RaisePropertyChanged(nameof(IsSelected));
                 OnCheckChanged();
             }
         }
     }
     private void OnSelectChanged()
     {
         foreach (var type in Collection)
         {
             //if type is selected and "Add" button is pressed then add the type to the List Scenario

         }
     }
           // I used RelayCommand to create the buttons and the execution
public MainWindowModel()
     {
         DeleteCommand = new RelayCommand(o => DeleteExecute());
         AddCommand = new RelayCommand(o => AddExecute());

     }
public ICommand DeleteCommand
     {
         get;
         private set;
     }
     public ICommand AddCommand
     {
         get;
         private set;
     }

     private void DeleteExecute()
     {
         Scenario.Clear();
     }

     private void AddExecute()
     {

        Scenario.Add(NewType);
     }
public Type NewType
     {
         get { return _newType; }
         set { SetPropertyAndFireEvent(ref _newType, value); }
     }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900