public PaletteViewModel(IContainer container, SampleTextViewModel sampleTextViewModel) { _container = container; SampleTextViewModel = sampleTextViewModel; BaseColorBrush = Observable.CombineLatest( RedValue, GreenValue, BlueValue, (r, g, b) => new SolidColorBrush(new Color { R = r, G = g, B = b, A = 255 })) .ToReactiveProperty <SolidColorBrush>() ; BaseColorBrush.Subscribe(x => { BaseColorBrush.Value.Freeze(); var hsl = HslColor.FromRgb(x.Color); ForegroundBrush.Value = hsl.L < 0.55 ? new SolidColorBrush(Colors.White) : new SolidColorBrush(Colors.Black); CreatePalette(x); ColorCode.Value = x.Color.R.ToString("x2") + x.Color.G.ToString("x2") + x.Color.B.ToString("x2"); }); ColorCode.Subscribe(x => { if (x.Length == 6) { RedValue.Value = byte.Parse(x.Substring(0, 2), System.Globalization.NumberStyles.HexNumber); GreenValue.Value = byte.Parse(x.Substring(2, 2), System.Globalization.NumberStyles.HexNumber); BlueValue.Value = byte.Parse(x.Substring(4, 2), System.Globalization.NumberStyles.HexNumber); } }); ToHtmlCommand.Subscribe(() => { using (var scope = _container.OpenScope()) { ClearFlash(); var service = scope.Resolve <HtmlGenerator>(); var content = service.Generate( PrimaryColors, ComplementalColors, AnalogousColors1, AnalogousColors2, TriadicColors1, TriadicColors2, VariantColors1, VariantColors2, WarningColors, ErrorColors, GrayScale ); Clipboard.SetText(content); ShowFlash("クリップボードにコピーしました。"); } }); ToCssCommand.Subscribe(() => { using (var scope = _container.OpenScope()) { ClearFlash(); var service = scope.Resolve <CssGenerator>(); var content = service.Generate( PrimaryColors.Reverse(), ComplementalColors.Reverse(), AnalogousColors1.Reverse(), AnalogousColors2.Reverse(), TriadicColors1.Reverse(), TriadicColors2.Reverse(), VariantColors1.Reverse(), VariantColors2.Reverse(), WarningColors.Reverse(), ErrorColors.Reverse(), GrayScale.Reverse() ); Clipboard.SetText(content); ShowFlash("クリップボードにコピーしました。"); } }); ToWpfResourceCommand.Subscribe(() => { using (var scope = _container.OpenScope()) { ClearFlash(); var service = scope.Resolve <WpfResourceGenerator>(); var content = service.Generate( PrimaryColors.Reverse(), ComplementalColors.Reverse(), AnalogousColors1.Reverse(), AnalogousColors2.Reverse(), TriadicColors1.Reverse(), TriadicColors2.Reverse(), VariantColors1.Reverse(), VariantColors2.Reverse(), WarningColors.Reverse(), ErrorColors.Reverse(), GrayScale.Reverse() ); Clipboard.SetText(content); ShowFlash("クリップボードにコピーしました。"); } }); SelectColorCommand.Subscribe(brush => { SampleTextViewModel.SelectColorCommand.Execute(brush); }); }