From 1ac1a089560dab9fb067a0653fc6ce042e4e6f44 Mon Sep 17 00:00:00 2001 From: "VKMTHD\\franzjosefkober" <franz.josef.kober@ivt.tugraz.at> Date: Sun, 10 May 2020 15:52:59 +0200 Subject: [PATCH] added validationrule for integer and double values, SIValueConverter for double values is only called at LostFocus event --- .../Helper/Converter/SIValueConverter.cs | 3 +- VECTO3GUI/Helper/SerializeHelper.cs | 5 +- .../Helper/Validation/DoubleValidator.cs | 54 +++++++ .../Validation/DoubleValidatorConfig.cs | 75 +++++++++ .../Helper/Validation/IntegerValidator.cs | 86 ++--------- .../Validation/IntegerValidatorConfig.cs | 17 --- VECTO3GUI/VECTO3GUI.csproj | 2 + VECTO3GUI/ViewModel/Impl/JobEntry.cs | 3 +- .../Declaration/AirdragDeclarationView.xaml | 2 +- .../AuxiliariesDeclarationView.xaml | 18 ++- .../Declaration/CompleteVehicleBusView.xaml | 144 ++++++++++++++---- .../IntegerVectoParameterControl.xaml | 2 +- 12 files changed, 283 insertions(+), 128 deletions(-) create mode 100644 VECTO3GUI/Helper/Validation/DoubleValidator.cs create mode 100644 VECTO3GUI/Helper/Validation/DoubleValidatorConfig.cs diff --git a/VECTO3GUI/Helper/Converter/SIValueConverter.cs b/VECTO3GUI/Helper/Converter/SIValueConverter.cs index 79a71f0bab..8746f89b01 100644 --- a/VECTO3GUI/Helper/Converter/SIValueConverter.cs +++ b/VECTO3GUI/Helper/Converter/SIValueConverter.cs @@ -22,7 +22,8 @@ namespace VECTO3GUI.Helper.Converter return DependencyProperty.UnsetValue; } if (!(value is SI)) { - throw new Exception("Can only convert SI types!"); + return DependencyProperty.UnsetValue; + //throw new Exception("Can only convert SI types!"); } var siValue = value as SI; diff --git a/VECTO3GUI/Helper/SerializeHelper.cs b/VECTO3GUI/Helper/SerializeHelper.cs index 8b1696f7b6..9db85364a9 100644 --- a/VECTO3GUI/Helper/SerializeHelper.cs +++ b/VECTO3GUI/Helper/SerializeHelper.cs @@ -19,7 +19,8 @@ namespace VECTO3GUI.Helper var settings = new JsonSerializerSettings { Formatting = Formatting.Indented, - DateFormatString = DATE_FORMAT + DateFormatString = DATE_FORMAT, + NullValueHandling = NullValueHandling.Ignore }; if (resolver != null) @@ -36,7 +37,7 @@ namespace VECTO3GUI.Helper using (var file = File.OpenText(filePath)) { var serializer = new JsonSerializer(); - serializer.DateFormatString = DATE_FORMAT; + serializer.DateFormatString = DATE_FORMAT; if (resolver != null) serializer.ContractResolver = resolver; diff --git a/VECTO3GUI/Helper/Validation/DoubleValidator.cs b/VECTO3GUI/Helper/Validation/DoubleValidator.cs new file mode 100644 index 0000000000..2b6d57539a --- /dev/null +++ b/VECTO3GUI/Helper/Validation/DoubleValidator.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Controls; + +namespace VECTO3GUI.Helper.Validation +{ + public class DoubleValidator : ValidationRule + { + private DoubleValidatorConfig _doubleValidator; + + public int MinValue { get; set; } + public int MaxValue { get; set; } + public int Decimals { get; set; } + + public DoubleValidator() { } + + public DoubleValidatorConfig ValidatorConfig + { + get { return _doubleValidator; } + set + { + _doubleValidator = value; + value?.SetValidator(this); + } + } + + public override ValidationResult Validate(object value, CultureInfo cultureInfo) + { + var strValue = value as string; + if (strValue != null) { + double number; + if(!double.TryParse(strValue, NumberStyles.Float, cultureInfo, out number)) + return new ValidationResult(false, "Not a valid number!"); + + if (number < MinValue) { + return new ValidationResult(false, $"Only values greater than or equals to {MinValue} are allowed!"); + } + + if (MaxValue > MinValue) + { + if (number > MaxValue) + return new ValidationResult(false, $"Only values less than or equals to {MaxValue} are allowed!"); + } + } + + return ValidationResult.ValidResult; + + } + } +} diff --git a/VECTO3GUI/Helper/Validation/DoubleValidatorConfig.cs b/VECTO3GUI/Helper/Validation/DoubleValidatorConfig.cs new file mode 100644 index 0000000000..6c67e33404 --- /dev/null +++ b/VECTO3GUI/Helper/Validation/DoubleValidatorConfig.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows; + +namespace VECTO3GUI.Helper.Validation +{ + public class DoubleValidatorConfig : Freezable + { + private DoubleValidator Validator { get; set; } + + public int MinValue + { + get { return (int)GetValue(MinValueProperty); } + set { SetValue(MinValueProperty, value); } + } + public static readonly DependencyProperty MinValueProperty = DependencyProperty.Register( + nameof(MinValue), typeof(int), typeof(DoubleValidatorConfig), new FrameworkPropertyMetadata(MinPropertyChangedCallback)); + + private static void MinPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + var doubleValidator = (DoubleValidatorConfig)d; + if (doubleValidator.Validator != null) + doubleValidator.Validator.MinValue = (int)e.NewValue; + } + + + public int MaxValue + { + get { return (int)GetValue(MaxValueProperty); } + set { SetValue(MaxValueProperty, value); } + } + public static readonly DependencyProperty MaxValueProperty = DependencyProperty.Register( + nameof(MaxValue), typeof(int), typeof(DoubleValidatorConfig), new FrameworkPropertyMetadata(MaxPropertyChangedCallback)); + + private static void MaxPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + var doubleValidator = (DoubleValidatorConfig)d; + if (doubleValidator.Validator != null) + doubleValidator.Validator.MaxValue = (int)e.NewValue; + } + + public int Decimals + { + get { return (int)GetValue(DecimalsProperty); } + set { SetValue(DecimalsProperty, value); } + } + public static readonly DependencyProperty DecimalsProperty = DependencyProperty.Register( + nameof(Decimals), typeof(int), typeof(DoubleValidatorConfig), new FrameworkPropertyMetadata(DecimalsPropertyChangedCallback)); + + private static void DecimalsPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + var doubleValidator = (DoubleValidatorConfig)d; + if (doubleValidator.Validator != null) + doubleValidator.Validator.Decimals = (int)e.NewValue; + } + + public void SetValidator(DoubleValidator validator) + { + Validator = validator; + if (validator != null) + { + validator.MaxValue = MaxValue; + validator.MinValue = MinValue; + validator.Decimals = Decimals; + } + } + + protected override Freezable CreateInstanceCore() + { + return new DoubleValidatorConfig(); + } + } +} diff --git a/VECTO3GUI/Helper/Validation/IntegerValidator.cs b/VECTO3GUI/Helper/Validation/IntegerValidator.cs index 86c43ebb05..10332b0027 100644 --- a/VECTO3GUI/Helper/Validation/IntegerValidator.cs +++ b/VECTO3GUI/Helper/Validation/IntegerValidator.cs @@ -2,9 +2,6 @@ using System.Collections.Generic; using System.Globalization; using System.Windows.Controls; -using System.Windows.Data; -using VECTO3GUI.ViewModel.Impl; -using VECTO3GUI.Views.CustomControls; namespace VECTO3GUI.Helper.Validation { @@ -14,13 +11,8 @@ namespace VECTO3GUI.Helper.Validation public int MinValue { get; set; } public int MaxValue { get; set; } - public bool ValidateInput { get; set; } - - - public IntegerValidator() - { - - } + + public IntegerValidator() {} public IntegerValidatorConfig ValidatorConfig { @@ -32,76 +24,24 @@ namespace VECTO3GUI.Helper.Validation } } - //public override ValidationResult Validate(object value, CultureInfo cultureInfo, BindingExpressionBase owner) - //{ - // var validateResult = base.Validate(value, cultureInfo, owner); - - // var dataItem = ((IntegerVectoParameterControl)((BindingExpression)owner).DataItem); - - - // if (dataItem.DataContext is CompleteVehicleBusViewModel) { - - // } - - - - - // //var exp = ((IntegerVectoParameterControl)((BindingExpression)owner).DataItem).Caption; - - - // //var t = ((IntegerVectoParameterControl)((BindingExpression)owner).ResolvedSource) .DataContext as CompleteVehicleBusViewModel; - // //t.InputValidationErrors = !validateResult.IsValid; - - // return validateResult; - - //} - public override ValidationResult Validate(object value, CultureInfo cultureInfo) { - - var strValue = value as string; - int number; - - if(!int.TryParse(strValue, out number)) - return new ValidationResult(false, "Not a valid integer value!"); - - if (!ValidateInput) - return ValidationResult.ValidResult; + if (strValue != null) { + int number; + if (!int.TryParse(strValue, out number)) + return new ValidationResult(false, "Not a valid integer value!"); - if (number < MinValue) - return new ValidationResult(false, $"Only integer values greater than or equals to {MinValue} are allowed!"); - - if(number > MaxValue) - return new ValidationResult(false, $"Only integer values less than or equals to {MaxValue} are allowed!"); + if (number < MinValue) + return new ValidationResult(false, $"Only integer values greater than or equals to {MinValue} are allowed!"); + if (MaxValue > MinValue) { + if (number > MaxValue) + return new ValidationResult(false, $"Only integer values less than or equals to {MaxValue} are allowed!"); + } + } return ValidationResult.ValidResult; } - - private void SetPropertyError(bool validationResult, string propertyName) - { - - - } - - - - - //protected void SetChangedProperty(bool changed, [CallerMemberName] string propertyName = "") - //{ - // if (!changed) - // { - // if (_changedInput.Contains(propertyName)) - // _changedInput.Remove(propertyName); - // } - // else - // { - // if (!_changedInput.Contains(propertyName)) - // _changedInput.Add(propertyName); - // } - - // UnsavedChanges = _changedInput.Count > 0; - //} } } diff --git a/VECTO3GUI/Helper/Validation/IntegerValidatorConfig.cs b/VECTO3GUI/Helper/Validation/IntegerValidatorConfig.cs index b344835237..c82e7c2817 100644 --- a/VECTO3GUI/Helper/Validation/IntegerValidatorConfig.cs +++ b/VECTO3GUI/Helper/Validation/IntegerValidatorConfig.cs @@ -43,23 +43,6 @@ namespace VECTO3GUI.Helper.Validation integerValidator.Validator.MaxValue = (int)e.NewValue; } - public bool ValidateInput - { - get { return (bool)GetValue(ValidateInputProperty); } - set { SetValue(ValidateInputProperty, value); } - } - - public static readonly DependencyProperty ValidateInputProperty = DependencyProperty.Register( - nameof(ValidateInput), typeof(bool), typeof(IntegerValidatorConfig), new FrameworkPropertyMetadata(ValidateInputPropertyChangedCallback)); - - private static void ValidateInputPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - var integerValidator = (IntegerValidatorConfig)d; - if (integerValidator.Validator != null) - integerValidator.Validator.ValidateInput = (bool)e.NewValue; - } - - private IntegerValidator Validator { get; set; } public void SetValidator(IntegerValidator validator) diff --git a/VECTO3GUI/VECTO3GUI.csproj b/VECTO3GUI/VECTO3GUI.csproj index 15a0c9d342..4e0e6013bb 100644 --- a/VECTO3GUI/VECTO3GUI.csproj +++ b/VECTO3GUI/VECTO3GUI.csproj @@ -177,6 +177,8 @@ <Compile Include="Helper\Converter\SaveButtonLabelConverter.cs" /> <Compile Include="Helper\SerializeHelper.cs" /> <Compile Include="Helper\TextBoxInputRegExBehaviour.cs" /> + <Compile Include="Helper\Validation\DoubleValidator.cs" /> + <Compile Include="Helper\Validation\DoubleValidatorConfig.cs" /> <Compile Include="Helper\Validation\IntegerValidatorConfig.cs" /> <Compile Include="Helper\Validation\IntegerValidator.cs" /> <Compile Include="Helper\ViewModelBase.cs" /> diff --git a/VECTO3GUI/ViewModel/Impl/JobEntry.cs b/VECTO3GUI/ViewModel/Impl/JobEntry.cs index 9133591f3b..1f01b76859 100644 --- a/VECTO3GUI/ViewModel/Impl/JobEntry.cs +++ b/VECTO3GUI/ViewModel/Impl/JobEntry.cs @@ -159,9 +159,8 @@ namespace VECTO3GUI.ViewModel.Impl } } } - - [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] + public class JobBody : ObservableObject { private string _completedVehicle; diff --git a/VECTO3GUI/Views/ComponentViews/Declaration/AirdragDeclarationView.xaml b/VECTO3GUI/Views/ComponentViews/Declaration/AirdragDeclarationView.xaml index 364fc1e7c1..4aebc7fcc3 100644 --- a/VECTO3GUI/Views/ComponentViews/Declaration/AirdragDeclarationView.xaml +++ b/VECTO3GUI/Views/ComponentViews/Declaration/AirdragDeclarationView.xaml @@ -84,7 +84,7 @@ Value="{Binding AppVersion}" IsEnabled="{Binding IsEditable}" /> <customControls:VectoParameterControl - Caption="DeclaredCd x A 0" CaptionWidthGroup="lblWidth" + Caption="DeclaredCd x A 0" CaptionWidthGroup="vehicleLbl" Unit="{helper:SIUnit DeclaredCdxA}" UnitWidthGroup="unitWidth" Value="{Binding DeclaredCdxA, Converter={converter:SIValueConverter}, ConverterParameter=double}" IsEnabled="{Binding IsEditable}"/> diff --git a/VECTO3GUI/Views/ComponentViews/Declaration/AuxiliariesDeclarationView.xaml b/VECTO3GUI/Views/ComponentViews/Declaration/AuxiliariesDeclarationView.xaml index 4f27683225..dbfd2fd033 100644 --- a/VECTO3GUI/Views/ComponentViews/Declaration/AuxiliariesDeclarationView.xaml +++ b/VECTO3GUI/Views/ComponentViews/Declaration/AuxiliariesDeclarationView.xaml @@ -10,6 +10,7 @@ xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks" xmlns:views="clr-namespace:VECTO3GUI.Views" xmlns:local="clr-namespace:VECTO3GUI.Views.ComponentViews.Declaration" + xmlns:validation="clr-namespace:VECTO3GUI.Helper.Validation" mc:Ignorable="d" d:DesignHeight="800" d:DesignWidth="800"> @@ -197,10 +198,21 @@ <ColumnDefinition SharedSizeGroup="unitWidth"/> </Grid.ColumnDefinitions> <TextBlock Grid.Column="0" Text="Aux Heater Power" Margin="0,0,10,0"/> - <TextBox Grid.Column="1" Margin="20,0,0,0" - Text="{Binding AuxHeaterPower, Converter={converter:SIValueConverter}, ConverterParameter=double, - Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}"/> + <TextBox Grid.Column="1" Margin="20,0,0,0"> + <TextBox.Resources> + <validation:IntegerValidatorConfig x:Key="IntValidator" MinValue="0" /> + </TextBox.Resources> + <TextBox.Text> + <Binding ValidatesOnDataErrors="True" NotifyOnValidationError="True" Path="AuxHeaterPower" + Converter="{converter:SIValueConverter}" ConverterParameter="int" UpdateSourceTrigger="PropertyChanged"> + + <Binding.ValidationRules> + <validation:IntegerValidator ValidatorConfig="{StaticResource IntValidator}"/> + </Binding.ValidationRules> + </Binding> + </TextBox.Text> + </TextBox> <TextBlock Grid.Row="0" Grid.Column="2" Text="{helper:SIUnit AuxHeaterPower}" Margin="5,0,5,0"/> </Grid> <!--<customControls:VectoParameterControl diff --git a/VECTO3GUI/Views/ComponentViews/Declaration/CompleteVehicleBusView.xaml b/VECTO3GUI/Views/ComponentViews/Declaration/CompleteVehicleBusView.xaml index 1c8634c96e..8de7983366 100644 --- a/VECTO3GUI/Views/ComponentViews/Declaration/CompleteVehicleBusView.xaml +++ b/VECTO3GUI/Views/ComponentViews/Declaration/CompleteVehicleBusView.xaml @@ -9,6 +9,7 @@ xmlns:helper="clr-namespace:VECTO3GUI.Helper" xmlns:converter="clr-namespace:VECTO3GUI.Helper.Converter" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" + xmlns:validation="clr-namespace:VECTO3GUI.Helper.Validation" mc:Ignorable="d" d:DesignHeight="800" d:DesignWidth="500"> @@ -120,6 +121,7 @@ <ColumnDefinition /> <ColumnDefinition SharedSizeGroup="unitWidth"/> </Grid.ColumnDefinitions> + <TextBlock Grid.Row="0" Grid.Column="0" Text="Registered Class" Margin="0,0,10,0"/> <ComboBox Grid.Column="1" Margin="20,0,0,0" @@ -144,6 +146,7 @@ <ColumnDefinition /> <ColumnDefinition SharedSizeGroup="unitWidth"/> </Grid.ColumnDefinitions> + <TextBlock Grid.Row="0" Grid.Column="0" Text="Vehicle Code" Margin="0,0,10,0"/> <ComboBox Grid.Column="1" Margin="20,0,0,0" @@ -161,23 +164,29 @@ Value="{Binding VehicleCode}" AllowedValues="{Binding AllowedVehicleCodes}" />--> - <Grid Margin="5"> <Grid.ColumnDefinitions> <ColumnDefinition SharedSizeGroup="vehicleLbl"/> <ColumnDefinition /> <ColumnDefinition SharedSizeGroup="unitWidth"/> </Grid.ColumnDefinitions> + <TextBlock Grid.Column="0" Text="Curb Mass Chassis" Margin="0,0,10,0"/> - <TextBox Grid.Column="1" Margin="20,0,0,0" - Text="{Binding CurbMassChassis, Converter={converter:SIValueConverter}, ConverterParameter=int, - Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}"/> - <TextBlock Grid.Row="0" Grid.Column="2" Text="{helper:SIUnit CurbMassChassis}" Margin="5,0,5,0"/> + <TextBox Grid.Column="1" Margin="20,0,0,0"> + <TextBox.Resources> + <validation:IntegerValidatorConfig x:Key="IntValidator" MinValue="500" /> + </TextBox.Resources> + <TextBox.Text> + <Binding ValidatesOnDataErrors="True" NotifyOnValidationError="True" Path="CurbMassChassis" + Converter="{converter:SIValueConverter}" ConverterParameter="int" UpdateSourceTrigger="PropertyChanged"> + <Binding.ValidationRules> + <validation:IntegerValidator ValidatorConfig="{StaticResource IntValidator}"/> + </Binding.ValidationRules> + </Binding> + </TextBox.Text> + </TextBox> + <TextBlock Grid.Column="2" Text="{helper:SIUnit CurbMassChassis}" Margin="5,0,5,0"/> </Grid> - <!--<customControls:VectoParameterControl - Caption="Curb Mass Chassis" Unit="{helper:SIUnit CurbMassChassis}" CaptionWidthGroup="vehicleLbl" UnitWidthGroup="unitWidth" - Value="{Binding CurbMassChassis, Converter={converter:SIValueConverter}, ConverterParameter=int}" />--> - <Grid Margin="5"> <Grid.ColumnDefinitions> @@ -185,10 +194,21 @@ <ColumnDefinition /> <ColumnDefinition SharedSizeGroup="unitWidth"/> </Grid.ColumnDefinitions> + <TextBlock Grid.Column="0" Text="Permissible Maximum Laden Mass" Margin="0,0,10,0"/> - <TextBox Grid.Column="1" Margin="20,0,0,0" - Text="{Binding TechnicalPermissibleMaximumLadenMass, Converter={converter:SIValueConverter}, ConverterParameter=int, - Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}"/> + <TextBox Grid.Column="1" Margin="20,0,0,0"> + <TextBox.Resources> + <validation:IntegerValidatorConfig x:Key="IntValidator" MinValue="3500" /> + </TextBox.Resources> + <TextBox.Text> + <Binding ValidatesOnDataErrors="True" NotifyOnValidationError="True" Path="TechnicalPermissibleMaximumLadenMass" + Converter="{converter:SIValueConverter}" ConverterParameter="int" UpdateSourceTrigger="PropertyChanged"> + <Binding.ValidationRules> + <validation:IntegerValidator ValidatorConfig="{StaticResource IntValidator}"/> + </Binding.ValidationRules> + </Binding> + </TextBox.Text> + </TextBox> <TextBlock Grid.Row="0" Grid.Column="2" Text="{helper:SIUnit TechnicalPermissibleMaximumLadenMass}" Margin="5,0,5,0"/> </Grid> <!--<customControls:VectoParameterControl @@ -227,8 +247,19 @@ <ColumnDefinition SharedSizeGroup="unitWidth"/> </Grid.ColumnDefinitions> <TextBlock Grid.Column="0" Text="Passengers Lower Deck" Margin="0,0,10,0"/> - <TextBox Grid.Column="1" Margin="20,0,0,0" - Text="{Binding NumberOfPassengersLowerDeck, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}"/> + <TextBox Grid.Column="1" Margin="20,0,0,0"> + <TextBox.Resources> + <validation:IntegerValidatorConfig x:Key="IntValidator" MinValue="0" /> + </TextBox.Resources> + <TextBox.Text> + <Binding ValidatesOnDataErrors="True" NotifyOnValidationError="True" Path="NumberOfPassengersLowerDeck" + UpdateSourceTrigger="PropertyChanged"> + <Binding.ValidationRules> + <validation:IntegerValidator ValidatorConfig="{StaticResource IntValidator}"/> + </Binding.ValidationRules> + </Binding> + </TextBox.Text> + </TextBox> </Grid> <!--<customControls:VectoParameterControl Caption="Passengers Lower Deck" Unit="" CaptionWidthGroup="vehicleLbl" UnitWidthGroup="unitWidth" @@ -242,8 +273,18 @@ <ColumnDefinition SharedSizeGroup="unitWidth"/> </Grid.ColumnDefinitions> <TextBlock Grid.Column="0" Text="Passengers Upper Deck" Margin="0,0,10,0"/> - <TextBox Grid.Column="1" Margin="20,0,0,0" - Text="{Binding NumberOfPassengersUpperDeck, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}"/> + <TextBox Grid.Column="1" Margin="20,0,0,0"> + <TextBox.Resources> + <validation:IntegerValidatorConfig x:Key="IntValidator" MinValue="0" /> + </TextBox.Resources> + <TextBox.Text> + <Binding ValidatesOnDataErrors="True" NotifyOnValidationError="True" Path="NumberOfPassengersUpperDeck" + UpdateSourceTrigger="PropertyChanged"> <Binding.ValidationRules> + <validation:IntegerValidator ValidatorConfig="{StaticResource IntValidator}"/> + </Binding.ValidationRules> + </Binding> + </TextBox.Text> + </TextBox> </Grid> <!--<customControls:VectoParameterControl Caption="Passengers Upper Deck" Unit="" CaptionWidthGroup="vehicleLbl" UnitWidthGroup="unitWidth" @@ -262,10 +303,19 @@ <ColumnDefinition SharedSizeGroup="unitWidth"/> </Grid.ColumnDefinitions> <TextBlock Grid.Column="0" Text="Height Integrated Body" Margin="0,0,10,0"/> - <TextBox Grid.Column="1" Margin="20,0,0,0" - Text="{Binding HeightIntegratedBody, Converter={converter:SIValueConverter}, ConverterParameter=double, - Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}"/> - + <TextBox Grid.Column="1" Margin="20,0,0,0"> + <TextBox.Resources> + <validation:DoubleValidatorConfig x:Key="DoubleValidator" MinValue="0" /> + </TextBox.Resources> + <TextBox.Text> + <Binding ValidatesOnDataErrors="True" NotifyOnValidationError="True" Path="HeightIntegratedBody" + Converter="{converter:SIValueConverter}" ConverterParameter="double3" UpdateSourceTrigger="LostFocus"> + <Binding.ValidationRules> + <validation:DoubleValidator ValidatorConfig="{StaticResource DoubleValidator}"/> + </Binding.ValidationRules> + </Binding> + </TextBox.Text> + </TextBox> <TextBlock Grid.Row="0" Grid.Column="2" Text="{helper:SIUnit HeightIntegratedBody}" Margin="5,0,5,0"/> </Grid> <!--<customControls:VectoParameterControl @@ -280,9 +330,19 @@ <ColumnDefinition SharedSizeGroup="unitWidth"/> </Grid.ColumnDefinitions> <TextBlock Grid.Column="0" Text="Vehicle Length" Margin="0,0,10,0"/> - <TextBox Grid.Column="1" Margin="20,0,0,0" - Text="{Binding VehicleLength, Converter={converter:SIValueConverter}, ConverterParameter=double, - Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}"/> + <TextBox Grid.Column="1" Margin="20,0,0,0"> + <TextBox.Resources> + <validation:DoubleValidatorConfig x:Key="DoubleValidator" MinValue="0" Decimals="3" /> + </TextBox.Resources> + <TextBox.Text> + <Binding ValidatesOnDataErrors="True" NotifyOnValidationError="True" Path="VehicleLength" + Converter="{converter:SIValueConverter}" ConverterParameter="double3" UpdateSourceTrigger="LostFocus"> + <Binding.ValidationRules> + <validation:DoubleValidator ValidatorConfig="{StaticResource DoubleValidator}"/> + </Binding.ValidationRules> + </Binding> + </TextBox.Text> + </TextBox> <TextBlock Grid.Row="0" Grid.Column="2" Text="{helper:SIUnit VehicleLength}" Margin="5,0,5,0"/> </Grid> <!--<customControls:VectoParameterControl @@ -297,9 +357,20 @@ <ColumnDefinition SharedSizeGroup="unitWidth"/> </Grid.ColumnDefinitions> <TextBlock Grid.Column="0" Text="Vehicle Width" Margin="0,0,10,0"/> - <TextBox Grid.Column="1" Margin="20,0,0,0" - Text="{Binding VehicleWidth, Converter={converter:SIValueConverter}, ConverterParameter=double, - Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}"/> + + <TextBox Grid.Column="1" Margin="20,0,0,0"> + <TextBox.Resources> + <validation:DoubleValidatorConfig x:Key="DoubleValidator" MinValue="0" Decimals="3" /> + </TextBox.Resources> + <TextBox.Text> + <Binding ValidatesOnDataErrors="True" NotifyOnValidationError="True" Path="VehicleWidth" + Converter="{converter:SIValueConverter}" ConverterParameter="double3" UpdateSourceTrigger="LostFocus"> + <Binding.ValidationRules> + <validation:DoubleValidator ValidatorConfig="{StaticResource DoubleValidator}"/> + </Binding.ValidationRules> + </Binding> + </TextBox.Text> + </TextBox> <TextBlock Grid.Row="0" Grid.Column="2" Text="{helper:SIUnit VehicleWidth}" Margin="5,0,5,0"/> </Grid> <!--<customControls:VectoParameterControl @@ -314,11 +385,28 @@ <ColumnDefinition SharedSizeGroup="unitWidth"/> </Grid.ColumnDefinitions> <TextBlock Grid.Column="0" Text="Entrance Height" Margin="0,0,10,0"/> - <TextBox Grid.Column="1" Margin="20,0,0,0" + <TextBox Grid.Column="1" Margin="20,0,0,0"> + <TextBox.Resources> + <validation:DoubleValidatorConfig x:Key="DoubleValidator" MinValue="0" Decimals="3" /> + </TextBox.Resources> + <TextBox.Text> + <Binding ValidatesOnDataErrors="True" NotifyOnValidationError="True" Path="EntranceHeight" + Converter="{converter:SIValueConverter}" ConverterParameter="double3" UpdateSourceTrigger="LostFocus"> + <Binding.ValidationRules> + <validation:DoubleValidator ValidatorConfig="{StaticResource DoubleValidator}"/> + </Binding.ValidationRules> + </Binding> + </TextBox.Text> + </TextBox> + + + + <!--<TextBox Grid.Column="1" Margin="20,0,0,0" Text="{Binding EntranceHeight, Converter={converter:SIValueConverter}, ConverterParameter=double, - Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}"/> + Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}"/>--> <TextBlock Grid.Row="0" Grid.Column="2" Text="{helper:SIUnit EntranceHeight}" Margin="5,0,5,0"/> </Grid> + <!--<customControls:VectoParameterControl Caption="Entrance Height" Unit="{helper:SIUnit EntranceHeight}" CaptionWidthGroup="vehicleLbl" UnitWidthGroup="unitWidth" Value="{Binding EntranceHeight, Converter={converter:SIValueConverter}, ConverterParameter=double}" />--> diff --git a/VECTO3GUI/Views/CustomControls/IntegerVectoParameterControl.xaml b/VECTO3GUI/Views/CustomControls/IntegerVectoParameterControl.xaml index 2271557a90..e878a4752a 100644 --- a/VECTO3GUI/Views/CustomControls/IntegerVectoParameterControl.xaml +++ b/VECTO3GUI/Views/CustomControls/IntegerVectoParameterControl.xaml @@ -21,7 +21,7 @@ <TextBlock Grid.Row="0" Grid.Column="0" Margin="0,0,10,0" Text="{Binding Caption}" /> <TextBox Grid.Row="0" Grid.Column="1" Margin="20,0,0,0" TextAlignment="{Binding ValueAlign}" x:Name="txtName" > <TextBox.Resources> - <validation:IntegerValidatorConfig x:Key="IntValidator" MinValue="{Binding MinValue}" MaxValue="{Binding MaxValue}" ValidateInput="{Binding ValidateInput}"/> + <validation:IntegerValidatorConfig x:Key="IntValidator" MinValue="{Binding MinValue}" MaxValue="{Binding MaxValue}"/> </TextBox.Resources> <!--http://geekswithblogs.net/NewThingsILearned/archive/2008/01/15/binding-to-an-attached-property.aspx--> <TextBox.Text > -- GitLab