From 9654056635b8650db577fb7807e90244283938da Mon Sep 17 00:00:00 2001 From: Kumar Devvrat Date: Tue, 29 Jun 2010 06:16:15 +0000 Subject: [PATCH] Indicate number range and type validation in the numeric editor through foreground colour git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/wpfdesigner@6008 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../PropertyGrid/Editors/NumberEditor.xaml.cs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/NumberEditor.xaml.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/NumberEditor.xaml.cs index f2b7b30012..3187f194ed 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/NumberEditor.xaml.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/NumberEditor.xaml.cs @@ -111,6 +111,42 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors ClearValue(LargeChangeProperty); } } + + public override void OnApplyTemplate() + { + base.OnApplyTemplate(); + TextBox textBox=Template.FindName("PART_TextBox",this) as TextBox; + if(textBox!=null) + textBox.TextChanged += TextValueChanged; + } + + private void TextValueChanged(object sender, TextChangedEventArgs e) + { + TextBox textBox = sender as TextBox; + if(PropertyNode==null) + return; + if(textBox==null) + return; + double val; + if(double.TryParse(textBox.Text, out val)){ + if(PropertyNode.FirstProperty.TypeConverter.IsValid(textBox.Text)){ + if(val >= Minimum && val <= Maximum){ + textBox.Foreground=Brushes.Black; + textBox.ToolTip=textBox.Text; + }else{ + textBox.Foreground = Brushes.DarkBlue; + textBox.ToolTip = "Value should be in between "+Minimum+" and "+Maximum; + } + }else{ + textBox.Foreground = Brushes.DarkRed; + textBox.ToolTip = "Cannot Convert to Type : " + PropertyNode.FirstProperty.ReturnType.Name; + } + }else{ + textBox.Foreground = Brushes.DarkRed; + textBox.ToolTip = string.IsNullOrWhiteSpace(textBox.Text)? null:"Value does not belong to any numeric type"; + } + + } ChangeGroup group;