Question

So in my (large) project, I've got a special date box that derives from a masked text box and thus has a "Format" property. It works by giving it a short date format, such as:

<extended:DateMaskTextBox Format="yyyy-MM-dd" />

Now at the start of the application, the ShortDatePattern property of the CultureInfo.CurrentCulture.DateTimeFormat object is set, depending on some logic. I would like to obtain this ShortDatePattern to use it as a value for my Format property of my DateMaskTextBox.

So far I've got this, and it is not working:

<extended:DateMaskTextBox Format="{Binding Source={x:Static glob:CultureInfo.CurrentCulture}, Path=DateTimeFormat.ShortDatePattern}" />

Any idea why this does not work? Thanks.

Was it helpful?

Solution

That Binding syntax is correct and should work just fine. Are you getting any binding errors in your output window? Have you tried displaying that same Binding on a TextBlock.Text in place of your control to just see if the string is coming through?

Without seeing its code I can't tell but I suspect that the problem may be with the DateMaskTextBox rather than the Binding. If the control is not set up correctly to respect newly set values of its Format property the bound value may not be getting used at all or be getting used too late to affect the behavior you're seeing when interacting with the control.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top