Hi,
I have a Datagrid with a DateTime field in it. By Default I get the XamDateTimeEditor to edit the Value of the Field.
Is it possible to set a minimun and maximum Date like in the XamMonthCalendar. (Disabled Date Ranges)
Or do you know an workarround how to limit the selection. Maybe something like using the MonthCalendar and styling it like the DateTimeEditor...
Yours sincrealy
Thomas
Hello Thomas,
The XamDateTimeEditor uses internally the month calendar when it is in edit mode. The ValueEditors have ValueConstraints which you can use to sex min - max range of the dates. Here is some sample code for doing so:
Style s = new Style(typeof(XamDateTimeEditor));
ValueConstraint constraint = new ValueConstraint();
constraint.MaxInclusive = new DateTime(2009, 10, 15);
constraint.MinExclusive = new DateTime(2009, 10, 1);
Setter st = new Setter(XamDateTimeEditor.ValueConstraintProperty, constraint);
s.Setters.Add(st);
Thank you for your help.
The Code you send me doesn't work for me. However, you helped me getting on the right way. Now I have an solution in the xaml that works for me:
<igDP:Field Name="RB_Date" Label="Datum"> <igDP:Field.Settings> <igDP:FieldSettings EditorType="{x:Type igDE:XamDateTimeEditor}"> <igDP:FieldSettings.EditorStyle> <Style TargetType="{x:Type igDE:ValueEditor}"> <Style.Setters> <Setter Property="ValueConstraint"> <Setter.Value> <igDE:ValueConstraint MinInclusive="01.10.2009" MaxInclusive="01.11.2009" /> </Setter.Value> </Setter> </Style.Setters> </Style> </igDP:FieldSettings.EditorStyle> </igDP:FieldSettings> </igDP:Field.Settings> </igDP:Field>
how can we bind MinInclusive or else to view model variable???
Hello,
I have created a sample project for you, with the functionality you want. Basically I used a help class with Min and Max Properties, which are used to connect the XamDateTimeEditor’s MinInclusive and MaxInclusive Properties with the external editors’ values, because the ValueConstraints can only be bound to a StaticResource. Please let me know if this helps you or you need further assistance on this matter.
Looking forward for your reply.
Most likely creating it in XAML is a better approach. Why is that you are looking to create the constraint in the code behind rather than in XAML? Is it just that you want to be able to change the constraints? If so, you can still define them in XAML and then access the resource and change them later. For example:
MyConstraint constraint = this.mainGrid.Resources["mc"] as MyConstraint;constraint.Max = DateTime.Today.AddDays(15);
Does this meet your needs? If not, what goal are you looking to accomplish?
Hi, I'm going through the same problem.
Your solution is working perfectly, but I can't see how to do the same but with an instance of MyConstraint defined in the code behind instead of the XAML code.
Here what I tried to do:
<igEditors:ValueConstraint MinInclusive="{Binding dateConst.Min}" MaxInclusive="{Binding dateConst.Max}"/> </Setter.Value>
in code behind :
dateConst = new MyConstraint(); dateConst.Max = new DateTime(2016, 12, 15); dateConst.Min = new DateTime(2015, 12, 15);
Thank you.