mvvm command (need to fix)
This commit is contained in:
62
PacticeSolution/MVVMButtonControl/ViewModel/ModelViewMain.cs
Normal file
62
PacticeSolution/MVVMButtonControl/ViewModel/ModelViewMain.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using MVVMButtonControl.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace MVVMButtonControl.ViewModel
|
||||
{
|
||||
internal class ModelViewMain
|
||||
{
|
||||
public ObservableCollection<Buttons> _buttonCollections;
|
||||
|
||||
public ICommand TestCommand { get; private set; }
|
||||
|
||||
public ICommand SubButtonCommand { get; private set; }
|
||||
|
||||
|
||||
public ModelViewMain()
|
||||
{
|
||||
_buttonCollections = new ObservableCollection<Buttons>();
|
||||
this.TestCommand = new RelayCommand<object>(CommandMethod);
|
||||
this.SubButtonCommand = new RelayCommand<object>(SubCommandMethod);
|
||||
}
|
||||
|
||||
public ObservableCollection<Buttons> ButtonCollection
|
||||
{
|
||||
get { return _buttonCollections; }
|
||||
set
|
||||
{
|
||||
if (_buttonCollections != null)
|
||||
_buttonCollections = value;
|
||||
}
|
||||
}
|
||||
|
||||
private void CommandMethod(object parameter)
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
this.ButtonCollection.Add(new Buttons { Name = $"Button {i}", SelectedColor = Brushes.Transparent });
|
||||
}
|
||||
}
|
||||
|
||||
private void SubCommandMethod(object parameter)
|
||||
{
|
||||
for (int i = 0; i < this.ButtonCollection.Count; i++)
|
||||
{
|
||||
this.ButtonCollection[i].SelectedColor = Brushes.Transparent;
|
||||
}
|
||||
|
||||
Buttons selected = this.ButtonCollection.Where(b => b.Name.Equals(parameter.ToString())).SingleOrDefault();
|
||||
if (selected == null)
|
||||
return;
|
||||
|
||||
selected.SelectedColor = Brushes.LightCoral;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user