I am trying to build a date range control with two XamDateTimeEditors.
I want to use ValueConstraint on each editor to restrict the value of the “From” date based on the user’s input “To” date and vice versa.
In the snippet below, the explicit setting of the MinInclusive on the “From” works as expected, but the Constraints that use binding do not seem to be working. I do not see any binding errors in VS output. Is it possible to use binding on ValueConstraint properties? If not, do I have to handle this in code behind OnEditModeEnding?
Also, I set the ValidateAsType to DateTime, will my explicit setting of MinInclusive fail if the culture does not match how I input the value?
<igEditors:XamDateTimeEditor Grid.Column="2"
x:Name="dtFromDate"
Value="{Binding Path=SelectedFromDate, ElementName=SPSUserControlBase, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Text="{Binding Path=SelectedFromDateString, ElementName=SPSUserControlBase, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<igEditors:XamDateTimeEditor.ValueConstraint>
<igEditors:ValueConstraint ValidateAsType="DateTime"
MinInclusive="1/1/1753"
MaxInclusive="{Binding Path=Value, ElementName=dtToDate, Mode=OneWay}" />
</igEditors:XamDateTimeEditor.ValueConstraint>
</igEditors:XamDateTimeEditor >
<igEditors:XamDateTimeEditor Value="{Binding Path=SelectedToDate, ElementName=SPSUserControlBase, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Text="{Binding Path=SelectedToDateString, ElementName=SPSUserControlBase, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Grid.Column="5"
x:Name="dtToDate" >
< igEditors:XamDateTimeEditor.ValueConstraint>
<igEditors:XamDateTimeEditor MinInclusive="{Binding Path=Value, ElementName=dtFromDate, Mode=OneWay}" />
</local: igEditors:XamDateTimeEditor.ValueConstraint>
Hello, I try to set ValueConstraint properties using Bindings, but is seems that they are not working.Setting explicitly the MInInclusiveValue in XAML will work even if the culture doesn’t match to the input value. The value automatically will be converted to supported format.You can handle the appropriate event OnEditModeEnding to set the ValueConstraint In the code and set the ValueConstaint using fallowing example:Style s = new Style(typeof(XamDateTimeEditor)); ValueConstraint vc = new ValueConstraint(); vc.MinInclusive = this.dtFromDate.Value; Setter setter = new Setter(XamDateTimeEditor.ValueConstraintProperty, vc); s.Setters.Add(setter); dtToDate.Style = s; I hope this help.Let me know if that would work in your scenario. Best Regards,DimiDeveloper Support EngineerInfragistics Inc
Thank you for your response.
I was able to assign the value constraints in the edit mode ending handlers.
However, I would prefer to handle this with binding. Will that be part of the 9.1 or any future release?
This is a limitation of the WPF framework. ElementName and DataContext binding for non-elements requires an inheritance context (which is currently internal in the WPF framework) or inheriting from freezable which imposes other issues.
Maybe you can bind the ValueConstraint property itself similar to what is discussed here?
I need to set the constraints by binding because I am using control templates, not the user controls. With control templates there is no code-behind reacting to some events available.
Is there any workaround available?
Hello, I did it like this using only XAML. There is no code behind.
Regards,
Franklin
XAML Code:
<
Window x:Class="WpfApplication2.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:igEditors="http://infragistics.com/Editors"
Title="Window1" Height="300" Width="300" >
<Grid>
<igEditors:XamDateTimeEditor HorizontalAlignment="Left" Name="xamDateTimeEditor1" VerticalAlignment="Top">
MaxInclusive="{Binding Source={x:Static sys:DateTime.Today}}" />
</igEditors:XamDateTimeEditor>
</Grid>
</
Window>