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)
{
}
}
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); }
}