public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { var theme = new ColorTheme(); try { // Check if we can parse the value if (!(value is string)) { return(base.ConvertFrom(context, culture, value)); } // If we got an empty string (empty input), just return some default theme if (value.ToString() == string.Empty) { return(ColorTheme.DeepSea()); } // Split the brushes string by the given seperator. // A brushes string looks like "#FF00CED1,#FFFF7F50,#FFFFFFFF,#FFFF8C00," (if the seperator is set to ',') // The first value is the respective value of the first property of the ColorTheme class, // The second value is the respective value of the second property of the ColorTheme class, // and so on... var brushesStrings = ((string)value).Split(Seperator); // Get properties of the ColorTheme class var brushesProperties = theme.GetType().GetProperties(); // Iterate properties for (var i = 0; i < brushesProperties.Count(); i++) { // Convert the hex string part to SolidColorBrush value // Using the example string a few lines above, brushesStrings[2] would be "#FFFFFFFF" var brush = (SolidColorBrush)(new BrushConverter().ConvertFrom(brushesStrings[i])); // Set the respective property of the colorTheme class brushesProperties[i].SetValue(theme, Convert.ChangeType(brush, brushesProperties[i].PropertyType), null); } } catch (Exception) { // If something bad happens when trying to parse & set the values, just return some default theme return(ColorTheme.DeepSea()); } return(theme); }
private void ColorThemeComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { switch (ColorThemeComboBox.SelectedIndex) { case 0: Properties.Settings.Default.SelectedColorTheme = ColorTheme.DeepSea(); break; case 1: Properties.Settings.Default.SelectedColorTheme = ColorTheme.SummerBreeze(); break; case 2: Properties.Settings.Default.SelectedColorTheme = ColorTheme.PurplePassion(); break; } }
////private void ServerChange_Click(object sender, RoutedEventArgs e) ////{ //// if (ViewModel.Role.Equals(ApplicationRole.Client)){ //// ViewModel.ChangeToServer(); //// } else //// { //// return; //// } ////} private void SetStandardColorsButton_OnClick(object sender, RoutedEventArgs e) { Properties.Settings.Default.SelectedColorTheme = ColorTheme.DeepSea(); }