I want to be able to change the ValueConstraint of a Field's numeric editor by binding to a property on the record's data context. This is my XAML:
<igWPF:Field Name="VarianceValue" Label="Variance"> <igWPF:Field.Settings> <igWPF:FieldSettings LabelPresenterStyle="{StaticResource VarianceTooltipHeaderStyle}" EditorType="{x:Type igWPF:XamNumericEditor}"> <igWPF:FieldSettings.EditorStyle> <Style TargetType="{x:Type igWPF:XamNumericEditor}"> <Setter Property="ValueConstraint"> <Setter.Value> <MultiBinding Converter="{StaticResource constraintConverter}"> <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="MinConstraint" /> <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="MaxConstraint" /> </MultiBinding> </Setter.Value> </Setter> </Style> </igWPF:FieldSettings.EditorStyle> </igWPF:FieldSettings> </igWPF:Field.Settings></igWPF:Field>
The 'MinConstraint' and 'MaxConstraint' are on the same object as the 'VarianceValue' property the field binds to.
- Atle
Hello Atle,
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.
Sweet, thanks! Those "DependencyProperty.UnsetValue" checks did the trick! I was just checking for null and such.
Hello again,
I can suggest you use the following code in the Converter's Convert method:
if (values[0] != DependencyProperty.UnsetValue && values[1] != DependencyProperty.UnsetValue) { return new ValueConstraint() { MinInclusive = Int32.Parse(values[0].ToString()), MaxInclusive = Int32.Parse(values[1].ToString()) }; } return Binding.DoNothing;
Allright, "DataItem" without RelativeSource seems to get a reference to the record's view model. However, when starting the application now, I get the following exception:
System.ArgumentException was unhandled Message=Must disconnect specified child from current parent Visual before attaching to new parent Visual.Source=PresentationCore
Got the same thing when trying to have a ValueConstraint property in my view model instead of the MultiBinding.
I can suggest you use the following Setter for the ValueConstraint Property instead of yours:
<Setter Property="ValueConstraint"> <Setter.Value> <MultiBinding Converter="{StaticResource constraintConverter}"> <Binding Path="DataItem.MinConstraint"/> <Binding Path="DataItem.MaxConstraint" /> </MultiBinding> </Setter.Value> </Setter>
Please let me know if this helps you or you need further assistance on this matter.