public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string input && context.Instance is SubFile parent) { //Entering in nothing means there's no limit if (string.IsNullOrWhiteSpace(input)) { return(null); } //Entering in one of the default names gies a static value if (DefaultNames.Contains(input)) { return(DefaultValues[DefaultNames.IndexOf(input)]); } //Everything else is an actual number bool hex; if (hex = (input.ToLower().StartsWith("0x") || input.ToLower().EndsWith("h"))) { input = Regex.Match(input, @"^(?:0x)?([0-9A-F]+)h?$", RegexOptions.IgnoreCase).Groups[1].Value; } return(ulong.TryParse(input, hex ? NumberStyles.HexNumber : NumberStyles.Integer, CultureInfo.CurrentCulture, out ulong output) ? output : value); }
private void addEventRow(string key, string name) { if (key == null) { key = ""; } if (Name == null) { Name = ""; } var txtName = new TextBox(); txtName.Margin = new Thickness(5); txtName.Text = name; txtName.SetValue(Grid.RowProperty, gridNames.RowDefinitions.Count); txtName.SetValue(Grid.ColumnProperty, 1); nameTextBoxes.Add(txtName); var txtKey = new TextBox(); txtKey.Margin = new Thickness(5); txtKey.Text = key; txtKey.Tag = key; txtKey.IsReadOnly = DefaultNames.ContainsKey(key); txtKey.SetValue(Grid.RowProperty, gridNames.RowDefinitions.Count); txtKey.SetValue(Grid.ColumnProperty, 0); txtName.Tag = txtKey; gridNames.Children.Add(txtKey); gridNames.Children.Add(txtName); if (!DefaultNames.ContainsKey(key)) { var btnRemove = new Button(); var image = new Image(); image.Source = (BitmapImage)FindResource("Remove"); btnRemove.Content = image; btnRemove.ToolTip = "Remove custom event name"; btnRemove.Margin = new Thickness(5); btnRemove.Tag = txtName; btnRemove.SetValue(Grid.RowProperty, gridNames.RowDefinitions.Count); btnRemove.SetValue(Grid.ColumnProperty, 2); btnRemove.Click += (sender, args) => { var button = (Button)sender; var txtName = (TextBox)button.Tag; var txtKey = (TextBox)txtName.Tag; nameTextBoxes.Remove(txtName); gridNames.Children.Remove(txtKey); gridNames.Children.Remove(txtName); gridNames.Children.Remove(button); if (Server.DiscordServerEventNames.ContainsKey(txtKey.Tag.ToString())) { if (!removeKeys.Contains(txtKey.Tag.ToString())) { removeKeys.Add(txtKey.Tag.ToString()); } } }; gridNames.Children.Add(btnRemove); } var rowDef = new RowDefinition(); rowDef.Height = GridLength.Auto; gridNames.RowDefinitions.Add(rowDef); }