Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
NumericUpDown Value not displayed #2515
I know it sounds weird, but the NumericUpDown control will not show a value if:
1.) it is part of a DataTemplate
I have created a small sample solution, that exhibits the problem:
The main window contains a ContentControl binding to the property "V" of the code-behind of the MainWindow class. It also contains a DataTemplate with two NumericUpDownControls. They are almost identical:
The only difference is that one of the controls also contains the following two attributes (one is sufficient to trigger the problem):
This control will not display the value bound to the NumericUpDown. The two attributes
of the Binding do not change the situation and neither does the StringFormat attribute. The BindingExpression seems to "vanish" - at least that is what I see in the WPF debugger of Visual Studio 2015. I can also see (thanks to the Binding diagnostics) that the converter is called and returns a correct value.
How did I find the problem: I exchanged all occurences of the DoubleUpDown from the Extended WPF Toolkit in my application with the MahApps.Metro NumericUpDown. The problem appeared only after this exchange.
Both NumericUpDownControls should display the same value.
Even though it sounds obscure, I just stumbled this same bug with exactly the same 3 criteria met. Everything works if I remove either the converter or the min and max properties. Otherwise I can see that it Convert is called on the converter, but no value is displayed. When value is set through the control's UI, ConvertBack is never called.
For me this seem to occur if the following are true.
A) The NumericUpDown is part of a DataTemplate
After looking through the source for 1.30 (as that is what I am currently dedicated to), i found that there seems to be issues with the order the Max, Min and Value properties are read in on load.
As I needed all 3, I figured out a work around.
Create a style for the NumericUpDown that checks the control's load flag and if it is loaded, set the max and min to the desired values.
The following is my full data template.
There is some bizarre behavior regarding conversion. I was using version 22.214.171.124 and yesterday I've decided to update to 1.4.3. As a result all my NumericUpDown usages broke - changes were not propagated from controls to viewmodels.
I've tried to find the reason, but could only find a "kludge" that partially helped.