1

Closed

Problem with convention binding to decimal property

description

When a Silverlight textbox is bound to a decimal property using conventions, it is not possible to type a number followed by a decimal point. As soon as the decimal point is entered it disappears and the cursor moves back to the beginning of the textbox.

ViewModel:
public class TestViewModel : Screen
{
private decimal anyNumber;
public decimal AnyNumber
{
    get { return anyNumber; }
    set
    {
        anyNumber = value;
        NotifyOfPropertyChange(() => AnyNumber);
    }
}
}

View:
<UserControl x:Class="SilverlightApplication1.TestView"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel>
<TextBox x:Name="AnyNumber" Width="200" />
</StackPanel>
</UserControl>
Closed Feb 15, 2011 at 6:23 PM by EisenbergEffect
Fixed in a40fcc024784
That was really interesting...Have a look at the code for kicks.

comments

EisenbergEffect wrote Feb 12, 2011 at 3:14 PM

That's strange. Have you tested this with TextBox and a regular binding? Perhaps it's related to the TextChanged event firing to update the binding?

alamb wrote Feb 14, 2011 at 3:07 PM

Using a regular binding works as expected - just the convention binding shows this behavior. It seems like the model is being updated as soon as the decimal point is typed, which fires a property change event and causes the view to update itself and reformat the number without the decimal point.

EisenbergEffect wrote Feb 15, 2011 at 1:56 AM

My guess is that you are correct. I'll try to look into it this week. I think I may be able to fix the problem with a custom value converter, added conventionally. We'll see.

rokos wrote May 5, 2014 at 10:48 AM

I just started to dig into caliburn micro this days and I stumbled into this Issue (I assume) with my first prototypes.

I use VS 2013 - CM 1.5.2 - WPF Client (NET 4.5). I am on German CultureInfo and I use ',' instead of '.' My TextBox is bound to a decimal? Property. Like alamb wrote, the changed event is fired after typing the ',' and the value falls back too its previous value ( the integer part without ',' ). I can enter a Value if i Type '12x,3' ignoring the error rectangle and then delete the 'x' afterward. After this nasty trick the value is set correct, and shown in its correct format '12,3'. (When I use '.' it is - also correctly - reformatted to be '123')

Is this a regression of this bug (fixed in 2011!?) in current version or did I miss something else?

chrisdotwood wrote Jun 25, 2014 at 1:05 PM

I have the same issue too with British CultureInfo (en-GB). Textbox bound to a double VS 2013 - CM 1.5.2 - WPF Client (NET 4.5).

When trying to enter 2.3 I can type the 2 but pressing the '.' doesn't append the decimal place then the 3 is added to give 23. At this point I can click the mouse and add the '.' in the middle.