I have 2 - XamDateTimeInput controls (Start & End dates), and I want to disable a Button control whenever either of these XamDateTimeInput controls have invalid input. Is there a way to do this in XAML?
Hello PMac, By saying that you would like to disable a Button control whenever any of the XamDateTimeInputs have an invalid input, I presume you mean that the value of the input is not a valid DateTime instance. If this is the case, since the XamDateTimeInput does not introduce a property that indicates whether the value is a valid DateTime object or not, an approach I can suggest you is to manually perform the validation operation in code-behind by handling the ValueChanged event of both Inputs with a shared handler.XAML: <ig:XamDateTimeInput x:Name="inputA" ValueChanged="input_ValueChanged" /><ig:XamDateTimeInput x:Name="inputB" ValueChanged="input_ValueChanged" /> Code-behind: private void input_ValueChanged(object sender, EventArgs e){ if (IsValidDateTime(inputA.Text) && IsValidDateTime(inputB.Text)) button.IsEnabled = true; else button.IsEnabled = false;} private bool IsValidDateTime(string text){ DateTime temp; return DateTime.TryParse(text, out temp);} This way whenever the value of one of the controls has been changed, the ValueChanged event will fire and the Button will get enabled or disabled respectively based on whether both controls have a valid DateTime value or not. I have attached a sample application, where the approach from above has been used. If you require any further assistance on this matter, please do not hesitate to ask.
Great thanks! I was hoping there was a property to bind so I could avoid code-behind. But if not, then this will work.
Also, I notice that my ig:XamDateTimeInput control frequently barks about the input date being invalid when its manually typed:
Value '' could not be converted
But the date IS valid. Not sure how to turn this feature off. Is it possible to disable the UI visual warnings?
Thank you. Is this property available in 14.1? I'm not seeing InvalidValueBehavior for the XamDateTimeInput control
Hello PMac, The InvalidValueBehavior exists in the WPF 14.1 Product version. For more detailed information on the property, you can take a look at Using XamDateTimeInput and InvalidValueBehavior Property and make sure you are using all the required assemblies for the control.
Ah, I see the property now. Thank you. But this only prevents the Dialog Message pupup box from displaying the error. The case that I am trying to suppress is the inline red warning message that is displayed as you type in the date. Is there a way to turn that feature off?
Hello PMac, The red warning message you have referred to is caused by the inability of the ValueConverter to convert the current value by returning null. In order to prevent this from happening, you can set the property you are binding to of a nullable type. This way the ValueConverter will accept the value whenever it is null as well and you should not be getting the message. public DateTime? FirstValue { get; set; } <ig:XamDateTimeInput x:Name="inputA" Value="{Binding FirstValue}" /> I have modified and attached my previous sample by binding the first input to a nullable DateTime property and the second input to a normal DateTime property. This way you should be able to see the difference. For more detailed information, you can take a look at the following thread, where a similar issue has been discussed. If you require any further assistance on the matter, please let me know.
Awesome, this worked. Thank you!
Hello PMac,
Thank you for your feedback. I am glad to know that I was able to help you achieve the functionality you were looking for. I believe this thread can help other people looking for a similar solution.
If you require any further assistance on this matter, please do not hesitate to ask.