Hi,
I need to basically ensure that the user does not select a date less than todays date. I tried to use the value constraint as below. I did not get this working since I try to attach a custom object as a value for the "MinInclusive" field.
If I give a hard coded date it validates correctly. Can anyone suggest how to bind my custom object to the MinInclusive field? Im using MVVM pattern
<igDP:Field Name="AuditScheduledDate">
<igDP:Field.Settings>
<igDP:FieldSettings EditorType="{x:Type igEdit:XamDateTimeEditor}" EditAsType="{x:Type Sys:DateTime}">
<igDP:FieldSettings.EditorStyle>
<Style TargetType="{x:Type igEdit:ValueEditor}">
<Style.Setters>
<Setter Property="ValueConstraint">
<Setter.Value>
<igEdit:ValueConstraint MinInclusive="{Binding Path=MinDate, Mode=TwoWay}" MaxInclusive="01/01/2050" />
</Setter.Value>
</Setter>
<Setter Property="InvalidValueBehavior" Value="RetainValue" />
</Style.Setters>
<Style.Triggers>
<Trigger Property="IsValueValid" Value="false">
<Trigger.Setters>
<Setter Property="BorderBrush" Value="Red" />
</Trigger.Setters>
</Trigger>
</Style.Triggers>
</Style>
</igDP:FieldSettings.EditorStyle>
</igDP:FieldSettings>
</igDP:Field.Settings>
</igDP:Field>
Thanks,
Ranjith
Hello,
I apologize that this post was not answered sooner. We are making the effort to ensure all posts are addressed by an Infragistics expert. I was wondering if you still need our assistance in this matter.
Looking at your XAML, the binding expression used in MinInclusive looks correct. The problem may be in what the object is that is being bound. Would you provide more information about the type of data being used here?
Thank you,
Hi Curtis,
I'm facing the same problem:
<
igDP:Field Name="fromDate" Label="Date">
<!--Binding="{Binding fromDate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">-->
<igDP:FieldSettings EditAsType="{x:Type sys:DateTime}">
<Style TargetType="{x:Type igEditors:XamDateTimeEditor}">
<Setter Property="Mask" Value="{}{date}" />
<Setter Property="InvalidValueBehavior" Value="DisplayErrorMessage" />
<igEditors:ValueConstraint MaxInclusive="{Binding Path=maxFromDate,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
<igEditors:ValueConstraint.Nullable>
<sys:Boolean>False</sys:Boolean>
</igEditors:ValueConstraint.Nullable>
<igEditors:ValueConstraint.MinInclusive>
<sys:DateTime>01/01/1900</sys:DateTime>
</igEditors:ValueConstraint.MinInclusive>
</igEditors:ValueConstraint>
My property maxFromDate in the view model is of a DateTime type. The values for max date is not bound at all!!!
Please help!
the problem is that the EditorStyle cannot find the ViewModel in order to bind to the DateTime property 'maxFromDate'. You need a way to point the Source of your binding expression to the ViewModel.
If your ViewModel is declared in your XAML in Resources, then you have access to it in XAML, otherwise, you'll need to add a hook to it (which is another topic).
Here is an example of declaring your ViewModel in XAML:
<UserControl.Resources>
<DataGridOverrides:MainViewModel x:Key="ViewModel" />
</UserControl.Resources>
And then accessing it in your style:
<igDP:FieldSettings
EditorType="{x:Type igEditors:XamDateTimeEditor}"
EditAsType="{x:Type System:DateTime}">
<igEditors:ValueConstraint
MinInclusive="{Binding Path=maxFromDate, Source={StaticResource ViewModel}}" />
If you are not instantiating the ViewModel in XAML (which would be the case if you are using Prism), then you can use a "ViewModel Locator". A Locator is used to locate a relative ViewModel for when the direct DataContext of an object does not point to the correct ViewModel (which is the case in this scenario where the Style is declared in a Field Settings declaration.
The following blogs describe how to implement a ViewModel Locator:
http://blog.alner.net/archive/2010/05/06/mvvm-viewmodel-locator-via-wpf-converters.aspx
http://johnpapa.net/simple-viewmodel-locator-for-mvvm-the-patients-have-left-the-asylum