I am using a xamDataGrid and there is a ValueConstraint with a fixed value of 30 for MaxInclusive.
I need to add a binding for MaxInclusive so that I can change it a run time but nothing seems to work.
How can I bind to the MaxInclusive property?
<igWPF:Field Name="Zone1Amps" Label ="Zone Current" Width="150"> <igWPF:Field.Settings> <igWPF:FieldSettings> <igWPF:FieldSettings.EditorStyle> <Style TargetType="igWPF:XamNumericEditor"> <Setter Property="IsEnabled" Value="{Binding IsEditEnabled, ElementName=rampGrid}" /> <Setter Property="Format" Value="0.000" /> <Setter Property="ValueType" Value="{x:Type System:Double}" /> <Setter Property="Mask" Value="{}{double:2.3}" /> <Setter Property="ValueConstraint"> <Setter.Value> <igEditors:ValueConstraint Nullable="False" MinInclusive="0" MaxInclusive="30" ValidateAsType="Double"/> </Setter.Value> </Setter> </Style> </igWPF:FieldSettings.EditorStyle> </igWPF:FieldSettings> </igWPF:Field.Settings> </igWPF:Field>
Hello Robert,
Thank you for the post.
You will not able to bind MaxInclusive at run time because that is not in the visual tree. Instead you would have to bind ValueConstraint. You can refer to this post might help you achieve it.
So how would I bind to the ValueConstraint?
Like this embedded code?
I found the article you mention but nothing seems to work including this.
<igWPF:Field Name="Zone1Amps" Label ="Zone Current" Width="150"> <igWPF:Field.Settings> <igWPF:FieldSettings> <igWPF:FieldSettings.EditorStyle> <Style TargetType="igWPF:XamNumericEditor"> <Setter Property="IsEnabled" Value="{Binding IsEditEnabled, ElementName=rampGrid}" /> <Setter Property="Format" Value="0.000" /> <Setter Property="ValueType" Value="{x:Type System:Double}" /> <Setter Property="Mask" Value="{}{double:2.3}" /> <Setter Property="ValueConstraint" Value="{Binding CurrentLimit, ElementName=rampGrid}" /> </Style> </igWPF:FieldSettings.EditorStyle> </igWPF:FieldSettings> </igWPF:Field.Settings> </igWPF:Field> public static readonly DependencyProperty CurrentLimitProperty = DependencyProperty.Register("CurrentLimit", typeof(double), typeof(NexxCustomXamDataGrid), new PropertyMetadata(30.0, OnNumberRspParamChanged)); public double CurrentLimit { get { return (double)GetValue(CurrentLimitProperty); } set { SetValue(CurrentLimitProperty, value); } } private static void OnNumberRspParamChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { NexxCustomXamDataGrid numberRspParam = e.NewValue as NexxCustomXamDataGrid; if (numberRspParam != null) { ValueEditor editor = d as ValueEditor; ValueConstraint constraint = editor.ValueConstraint; if (constraint == null) editor.ValueConstraint = constraint = new ValueConstraint(); constraint.SetValue(ValueConstraint.MaxInclusiveProperty, 15.0/*numberRspParam.MaxValue*/); constraint.SetValue(ValueConstraint.MinInclusiveProperty, 0.0/*numberRspParam.MinValue*/); } }
I found a way to get this working by creating a custom xamNumericEditor and adding a binding for the ValueConstraint inside.
public class PowerSupplyNumericEditor : XamNumericEditor { public PowerSupplyNumericEditor() { this.CurrentLimit = IsLuminaSupplyUsed() ? 6.0 : 30.0; } private bool IsLuminaSupplyUsed() { bool supplyUsed = false; IToolLayoutConfigurationUtility toolLayout = ToolLayoutConfigurationUtility.Instance; IPlatingPowerSupplyInfo[] powerSupplyInfoArray = toolLayout.PlatingPowerSupplyInfoArray; foreach (IPlatingPowerSupplyInfo powerSupplyInfo in powerSupplyInfoArray) { if (powerSupplyInfo.SubType == PlatingPowerSupplyType.Lumina10ChannelCurrent2) { supplyUsed = true; break; } } return supplyUsed; } public static readonly DependencyProperty CurrentLimitProperty = DependencyProperty.Register("CurrentLimit", typeof(double), typeof(PowerSupplyNumericEditor), new PropertyMetadata(0.0, OnLimitChanged)); public static readonly DependencyProperty ValueConstraintProperty = DependencyProperty.RegisterAttached("ValueConstraint", typeof(ValueConstraint), typeof(PowerSupplyNumericEditor)); public double CurrentLimit { get { return (double)GetValue(CurrentLimitProperty); } set { SetValue(CurrentLimitProperty, value); } } private static void OnLimitChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { ValueEditor editor = d as ValueEditor; ValueConstraint constraint = editor.ValueConstraint; if (constraint == null) editor.ValueConstraint = constraint = new ValueConstraint(); constraint.SetValue(ValueConstraint.MaxInclusiveProperty, (double)e.NewValue); constraint.SetValue(ValueConstraint.MinInclusiveProperty, 0.0); } } <igWPF:Field Name="Zone1Amps" Label ="Zone Current" Width="150"> <igWPF:Field.Settings> <igWPF:FieldSettings> <igWPF:FieldSettings.EditorStyle> <Style TargetType="local:PowerSupplyNumericEditor"> <Setter Property="IsEnabled" Value="{Binding IsEditEnabled, ElementName=rampGrid}" /> <Setter Property="Format" Value="0.000" /> <Setter Property="ValueType" Value="{x:Type System:Double}" /> <Setter Property="Mask" Value="{}{double:2.3}" /> <Setter Property="ValueConstraint" Value="{Binding CurrentLimit}" /> </Style> </igWPF:FieldSettings.EditorStyle> </igWPF:FieldSettings> </igWPF:Field.Settings> </igWPF:Field>
Thank you for your help.
Hello,
Thank you for the update. Glad you fond the solution.