public MainWindowViewModel(ColorManager colorManager, ViewModelFactory viewModelFactory) { addCommand = new DelegateCommand(Add, CanAdd); this.colorManager = colorManager; modelFactory = viewModelFactory; colorManager.ColorAdded += (sender, e) => { ColorViewModel color = modelFactory.CreateColorViewModel(e.Color); colors.Add(color); UpdateAdditionStatus(); }; colorManager.ColorDeleted += (sender, e) => { foreach (ColorViewModel color in colors) { if (color.ColorCode.Equals(e.Color.CodeTheColor)) { colors.Remove(color); UpdateAdditionStatus(); break; } } }; //для colorA то есть для "alpha" устанавливается максимальное значение! colorA = 255; ConvertingToHexadecimalSystem(); OnPropertyChanced(new PropertyChangedEventArgs(nameof(ColorCode))); }
public MainWindowViewModel(IColorManager colorManager, IViewModelFactory viewModelFactory) { this.colorManager = colorManager; this.viewModelFactory = viewModelFactory; addCommand = new DelegateCommand(Add); currentColor = Color.FromArgb((byte)alpha, (byte)red, (byte)green, (byte)blue); this.colorManager.ColorAdded += (sender, e) => { ColorViewModel color = viewModelFactory.CreateColorViewModel(e.Color); colors.Add(color); OnPropertyChanged(new PropertyChangedEventArgs(nameof(CanAdd))); }; this.colorManager.ColorDeleted += (sender, e) => { foreach (ColorViewModel color in colors) { if (color.Name.Equals(e.Color.ToString())) { colors.Remove(color); break; } } OnPropertyChanged(new PropertyChangedEventArgs(nameof(CanAdd))); }; PropertyChanged += (sender, e) => { if (e.PropertyName.Equals(nameof(Alpha)) || e.PropertyName.Equals(nameof(Red)) || e.PropertyName.Equals(nameof(Green)) || e.PropertyName.Equals(nameof(Blue))) { UpdateColor(); OnPropertyChanged(new PropertyChangedEventArgs(nameof(CanAdd))); } }; }