public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { // obtain the converter to string TypeConverter converter = TypeDescriptor.GetConverter(typeof(string)); if (parameter != null) { value = parameter; } string key; // Auto-convert from any type to string try { // determine if the supplied value is of a suitable type if (converter.CanConvertFrom(value.GetType())) { // return the converted value key = (string)converter.ConvertFrom(value); } else { // try to convert from the string representation key = (string)converter.ConvertFrom(value.ToString()); } } catch (Exception) { key = (string)value; } return(LimeLanguage.Translate(LanguageSection, key, key)); }
protected override void OnPropertyChanged(LimeProperty prop, PropertyChangedEventArgs e) { if (string.IsNullOrEmpty(e.PropertyName) || e.PropertyName == "Content") { if (prop == null) { wxText.Text = ""; } else if (prop.Content != null) { if (Translate) { wxText.Text = LimeLanguage.Translate(LanguageSection, prop.Value, prop.Value); } else { wxText.Text = prop.Value; } } else { wxText.Text = prop.Name; } } }
/// <summary> /// Provide the ItemsSource /// </summary> /// <param name="serviceProvider"></param> /// <returns>ItemsSource as a array of ItemsSourceType</returns> public override object ProvideValue(IServiceProvider serviceProvider) { var enums = Enum.GetNames(_type); var ret = new Dictionary <string, string>(); for (int i = 0; i < enums.Length; i++) { var keyval = string.Format("{0}.{1}.name", _type.Name, enums[i]); ret.Add(enums[i], LimeLanguage.Translate(LanguageSection, keyval, keyval)); } return(ret); }
/// <summary> /// Provide the Translated key /// </summary> /// <param name="serviceProvider"></param> /// <returns>ItemsSource as a array of ItemsSourceType</returns> public override object ProvideValue(IServiceProvider serviceProvider) { if (string.IsNullOrEmpty(Key)) { return(""); } string keyval = Format != null?string.Format(Format, Key) : Key; string ret = LimeLanguage.Translate(Section, keyval, keyval); return(ret); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { string sep = LimeLanguage.Translate("Text", "ListSeparator", ", "); if (value is IEnumerable <string> list) { return(string.Join(sep, list)); } else if (value == null) { return(""); } return(new ValidationResult(false, "ListToStringConverter: Type not supported: " + value.GetType())); }
public ItemViewModel(string key, Type type) { Key = key; if (type != null) { var keyval = string.Format("{0}.{1}.name", type.Name, key); var translated = LimeLanguage.Translate(LanguageSection, keyval, key); keyval = string.Format("{0}.{1}.desc", type.Name, key); var desc = LimeLanguage.Translate(LanguageSection, keyval); string tooltip = keyval != desc ? desc : null; Name = translated; Desc = tooltip; } else { Name = key; } }
private void ValidateValue(bool set) { var prop = wxMain.DataContext as LimeProperty; var type = prop.Type; if (set) { prop.Value = Cache; } if (wxMenu.SelectedItem is ItemViewModel item) { wxText.Text = item.Name; } else if (type.IsEnum && type.IsDefined(typeof(FlagsAttribute), inherit: false)) { var sep = LimeLanguage.Translate("Text", "ListSeparator", ", "); var sb = new StringBuilder(); foreach (ListBoxItem wxObj in wxMenu.Items) { var wxcheck = (CheckBox)wxObj.Content; var content = wxcheck.Content as string; if (wxcheck.IsChecked == true) { if (sb.Length != 0) { sb.Append(sep); } sb.Append(content); } } wxText.Text = sb.ToString(); } else { wxText.Text = prop.Value; } }
private static void OnOptionsEnabledPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (!(d is LimeControl wxThis)) { return; } var prop = wxThis.DataContext as LimeProperty; if (wxThis.MainGrid != null && prop != null) { var wxobj = WPF.FindFirstChild <StackPanel>(wxThis.MainGrid); wxobj.Children.Clear(); if ((bool)e.NewValue) { if (prop.ReqAdmin) { wxobj.Children.Add(new LimeIcon() { IconKey = "Shield", ToolTip = LimeLanguage.Translate(LanguageSection, "ShieldTip", "ShieldTip") }); } if (prop.ReqRestart) { wxobj.Children.Add(new LimeIcon() { IconKey = "Warning", ToolTip = LimeLanguage.Translate(LanguageSection, "RestartTip", "RestartTip") }); } } } wxThis.OnOptionsEnabledPropertyChanged(e); }
/// <summary> /// Trigger on DataContext change event. /// </summary> /// <param name="sender">LimeProperty source</param> /// <param name="e">Binding change if null</param> public void TriggerDataContextChanged(object sender, PropertyChangedEventArgs e) { var prop = sender as LimeProperty; // Options Handling if (MainGrid != null && (string.IsNullOrEmpty(e.PropertyName) || e.PropertyName == "ReqAdmin" || e.PropertyName == "ReqRestart")) { var count = VisualTreeHelper.GetChildrenCount(MainGrid); if (VisualTreeHelper.GetChild(MainGrid, 0) is StackPanel wxobj && count > 1) { wxobj.Children.Clear(); if (OptionsEnabled && prop != null) { if (prop.ReqAdmin) { wxobj.Children.Add(new LimeIcon() { IconKey = "Shield", ToolTip = LimeLanguage.Translate(LanguageSection, "ShieldTip", "ShieldTip") }); } if (prop.ReqRestart) { wxobj.Children.Add(new LimeIcon() { IconKey = "Warning", ToolTip = LimeLanguage.Translate(LanguageSection, "RestartTip", "RestartTip") }); } } } } // Header Handling if (MainGrid != null && (string.IsNullOrEmpty(e.PropertyName) || e.PropertyName == "Name")) { TextBlock wxobj = null; int idx = 1; var count = VisualTreeHelper.GetChildrenCount(MainGrid); if (count > 2) { wxobj = VisualTreeHelper.GetChild(MainGrid, idx) as TextBlock; } if (wxobj == null && count > 1) { wxobj = VisualTreeHelper.GetChild(MainGrid, idx = 0) as TextBlock; // no options } if (wxobj != null) { var wxcol = MainGrid.ColumnDefinitions[idx]; if (HeaderEnabled && prop != null && !string.IsNullOrWhiteSpace(prop.Name)) { wxobj.Visibility = Visibility.Visible; wxcol.SharedSizeGroup = GridGroupColHeader; } else { wxobj.Visibility = Visibility.Collapsed; wxcol.SharedSizeGroup = null; } } } // Visibility Handling if (string.IsNullOrEmpty(e.PropertyName) || e.PropertyName == "Visible") { Visibility = prop == null || prop.Visible ? Visibility.Visible : Visibility.Collapsed; } // Callback control OnPropertyChanged(prop, e); // Value Handling if (string.IsNullOrEmpty(e.PropertyName) || e.PropertyName == "Content") { var value = prop?.Content; var ev = new LimeControlEventArgs(this, sender, value); //LimeMsg.Debug("LimeTextBox TriggerDataContextChanged"); Base.ValueValidated?.Invoke(this, ev); } }
protected override void OnPropertyChanged(LimeProperty prop, PropertyChangedEventArgs e) { if (string.IsNullOrEmpty(e.PropertyName) || e.PropertyName == "Icon" || e.PropertyName == "Type") { // Free previous resources of the control if (Content is ButtonBase wxobj) { wxobj.PreviewKeyDown -= FixFocus_PreviewKeyDown; wxobj.IsEnabledChanged -= Button_IsEnabledChanged; } // Create the Content of the wxMain Border: // <ButtonBase ToolTip="{Binding Desc}" PreviewKeyDown="FixFocus_PreviewKeyDown"> // <StackPanel x:Name="wxPanel" Orientation="Horizontal"> // </StackPanel> // </ButtonBase> ButtonBase wxButton; if (prop.Type == typeof(bool) || prop.Type == typeof(bool?)) { wxButton = new ToggleButton(); wxButton.SetBinding(ToggleButton.IsCheckedProperty, new Binding("Content")); } else { wxButton = new Button(); wxButton.SetBinding(ButtonBase.CommandProperty, new Binding("Content")); } wxButton.SetBinding(ToolTipProperty, new Binding("Desc")); wxButton.PreviewKeyDown += FixFocus_PreviewKeyDown; wxButton.IsEnabledChanged += Button_IsEnabledChanged; wxButton.Content = new StackPanel() { Orientation = Orientation.Horizontal }; wxMain.Child = wxButton; } var wxPanel = (Panel)((ButtonBase)wxMain.Child).Content; if (string.IsNullOrEmpty(e.PropertyName) || e.PropertyName == "Name" || e.PropertyName == "ReqAdmin" || e.PropertyName == "ReqRestart" || e.PropertyName == "Icon") { wxPanel.Children.Clear(); if (prop.ReqAdmin) { wxPanel.Children.Add(new LimeIcon() { IconKey = "Shield", ToolTip = LimeLanguage.Translate(LanguageSection, "ShieldTip", "ShieldTip") }); } if (prop.ReqRestart) { wxPanel.Children.Add(new LimeIcon() { IconKey = "Warning", ToolTip = LimeLanguage.Translate(LanguageSection, "RestartTip", "RestartTip") }); } if (!string.IsNullOrEmpty(prop.Icon)) { wxPanel.Children.Add(new LimeIcon() { IconKey = prop.Icon }); } wxPanel.Children.Add(new TextBlock() { Text = prop.Name }); } }