You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.8 KiB
62 lines
1.8 KiB
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;
|
|
}
|
|
}
|
|
}
|
|
|