Silverlight 5 binding on a property with logic in its setter does not work as expected when debug is attached

My problem is pretty easy to reproduce.
I created a project from scratch with a view model.
As you can see in the setter of "Age" property I have a simple logic.
    public class MainViewModel : INotifyPropertyChanged
            public event PropertyChangedEventHandler PropertyChanged;
            private int age;
            public int Age
                get
                    return age;
                set
                    /*Age has to be over 18* - a simple condition in the setter*/
                    age = value;
                    if(age <= 18)
                        age = 18;
                    OnPropertyChanged("Age");
            public MainViewModel(int age)
                this.Age = age;
            private void OnPropertyChanged(string propertyName)
                if (this.PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
In the MainPage.xaml 
     <Grid x:Name="LayoutRoot" Background="White">
            <TextBox 
                Text="{Binding Path=Age, Mode=TwoWay}" 
                HorizontalAlignment="Left"
                Width="100"
                Height="25"/>
            <TextBlock
                Text="{Binding Path=Age, Mode=OneWay}"
                HorizontalAlignment="Right"
                Width="100"
                Height="25"/>
        </Grid>
And MainPage.xaml.cs I simply instantiate the view model and set it as a DataContext.
    public partial class MainPage : UserControl
        private MainViewModel mvm;
        public MainPage()
            InitializeComponent();
            mvm = new MainViewModel(20);
            this.DataContext = mvm;
I expect that this code will limit set the Age to 18 if the value entered in the TextBox is lower than 18.
Scenario: Insert into TextBox the value "5" and press tab (for the binding the take effect, TextBox needs to lose the focus)
Case 1: Debugger is attached =>
TextBox value will be "5" and TextBlock value will be "18" as expected. - WRONG
Case 2: Debugger is NOT attached => 
TextBox value will be "18" and TextBlock value will be "18" - CORRECT
It seems that when debugger is attached the binding does not work as expected on the object that triggered the update of the property value. This happens only if the property to which we are binding has some logic into the setter or getter.
Has something changed in SL5 and logic in setters is not allowed anymore?
Configuration:
VisualStudio 2010 SP1
SL 5 Tools 5.1.30214.0
SL5 sdk 5.0.61118.0
IE 10
Thanks!                                       

Inputting the value and changing it straight away is relatively rare.
Very few people are now using Silverlight because it's kind of deprecated...
This is why nobody has reported this.
I certainly never noticed this problem and I have a number of live Silverlight systems out there.
Some of which are huge.
If you want a "fix":
private void OnPropertyChanged(string propertyName)
if (this.PropertyChanged != null)
//PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
Storyboard sb = new Storyboard();
sb.Duration = new Duration(new TimeSpan(0, 0, 0, 0, 100));
sb.Completed += delegate
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
sb.Begin();
The fact this works is interesting because (I think ) it means the textbox can't be updated at the point the propertychanged is raised.
Please don't forget to upvote posts which you like and mark those which answer your question.
My latest Technet article - Dynamic XAML

Similar Messages

  • When streaming a movie with the new Apple TV, and using a DSL Internet connection, all audio sound works, e.g., the music track, but the audio track with the actor's voices, does not work. What can I do?

    When streaming a movie with the new Apple TV, and using a DSL Internet connection, all audio sound works, e.g., the music track, but the audio track with the actor's voices, does not work. What can I do?

    Hi Brian,
    Thanks restoring and restarting didn't fix my problem - i have started it fresh and still it doesn't work. Basically I press ONCE on the remote, after the machine has not had any commands for 10 minutes, and the cursor skips from one end of the menu to the other - so I can't choose network or update software etc - I sometimes manage to stop it randomly in the middle of the menu if I press on a command in the middle of the cursor skipping all the menu steps...not sure what the problem is but I have basically not used my brand new apple tv since I bought it for that reason! I should call Apple support I suppose! grrrr hate wasting time with stuff like this!
    Thanks for your help though!
    Pernille

  • The message function on my Ipad just quit working.  I was using it while in Mexico and it just quit.  I have come home and synced my Ipad with Itunes and function still does not work.  How do I get this function to work again?

    The message function on my Ipad just quit working.  I was using it while in Mexico and it just quit.  I have come home and synced my Ipad with Itunes and function still does not work.  How do I get this function to work again?

    When I use find file http://www.macupdate.com/app/mac/30073/find-file (which does tend to find files that "Finder" can't), it's not coming up with any other itunes library files that have been modified in the past week, which I know it would have been - unfortunately, I don't have a very recent backup of the hard drive.  It would be a few months old so it wouldn't have the complete library on it....any ideas?  I'm wondering if restarting the computer might help but have been afraid to do so in case it would make it harder to recover anything...I was looking at this thread https://discussions.apple.com/thread/4211589?start=0&tstart=0 in the hopes that it might have a helpful suggestion but it's definitely a different scenario.

  • I look for integrated in the legend bloc of diaporama, a widget such as "Accordion" for, with a click, or passing with mouse, open a new legend for each photo. I tried with "Accordion" of Muse, it does not work. I tried copy/paste, mais no result. The wid

    Question.
    I look for integrated in the legend bloc of diaporama, a widget such as "Accordion" for, with a click, or passing with mouse, open a new legend for each photo. I tried with "Accordion" of Muse, it does not work. I tried copy/paste, mais no result. The widget disappear in bloc legend. disparaître. Have you one solution?
    Thank you,
    Loïc

    Accordion or Tabbed panel should to it, with click and open container.
    Please provide site url where this does not work, also if you can provide an example where we can see the exact action then it would help us.
    Thanks,
    Sanjit

  • [svn:fx-trunk] 5019: ASDoc updates to indicate that some Halo containers do not work with the Spark equiv (ControlBar does not work with Spark Panel/ AppControlBar does not work with Spark Application), and indicate that Canvas, Box, Tile, Panel have Spa

    Revision: 5019
    Author: [email protected]
    Date: 2009-02-19 13:17:21 -0800 (Thu, 19 Feb 2009)
    Log Message:
    ASDoc updates to indicate that some Halo containers do not work with the Spark equiv (ControlBar does not work with Spark Panel/AppControlBar does not work with Spark Application), and indicate that Canvas, Box, Tile, Panel have Spark equivs
    QE Notes: None
    Doc Notes: None
    Bugs: -
    Modified Paths:
    flex/sdk/trunk/frameworks/projects/framework/src/mx/containers/Accordion.as
    flex/sdk/trunk/frameworks/projects/framework/src/mx/containers/ApplicationControlBar.as
    flex/sdk/trunk/frameworks/projects/framework/src/mx/containers/Box.as
    flex/sdk/trunk/frameworks/projects/framework/src/mx/containers/Canvas.as
    flex/sdk/trunk/frameworks/projects/framework/src/mx/containers/ControlBar.as
    flex/sdk/trunk/frameworks/projects/framework/src/mx/containers/HBox.as
    flex/sdk/trunk/frameworks/projects/framework/src/mx/containers/Panel.as
    flex/sdk/trunk/frameworks/projects/framework/src/mx/containers/TabNavigator.as
    flex/sdk/trunk/frameworks/projects/framework/src/mx/containers/Tile.as
    flex/sdk/trunk/frameworks/projects/framework/src/mx/containers/VBox.as
    flex/sdk/trunk/frameworks/projects/framework/src/mx/containers/ViewStack.as

    Hi DST
    This is a great effort and gesture. thank you on behalf of all the newbies.
    PJ

  • HT4623 i updated my ipad with ios7 but the keyboard does not work as it should hit the letters it is slow and does not click as it should

    updated my ipad with ios7 but the keyboard does not work its slow when i hit the letters does not click did not do this until i updated anyone can help me on this to fix it

    Settings>General>Reset>Reset All Settings

  • For what reason on my tablet with OS Android 4.1 does not work flash on the sites?

    Hi! I recently bought a Google Nexus 7 tablet with Android 4.1 operating system and on my tablet does not work flash sites. Why adobe does not release a new version of flash for android 4.1? Why it was necessary to buy a company Macromedia, if adobe does not want to develop web technology? I think against Adobe can sue for violation of antitrust

    I found this for example:
    http://www.slashgear.com/adobe-no-jelly-bean-flash-flash-player-pulled-altogether-august-1 5-29236404/

  • Problems with compressing  files with right hand click. it does not work.

    Problems with compressing files with right hand click.
    I am using the compress function in the Mac OS (File > Compress XX) from time to time. Today it does not work anymore. OS 10.5.6
    I get a message: The content list cannot be created for compressing.
    I tried it with files and folders and keep getting this message. Anybody any idea as to how to fix this

    Thanks I love my macbook!!!!
    I also got further problems such as copy-paste not working etc.
    so I fixed it just this morning by running Applejack 1.5 and am back up running noticing your post.
    thanks for helping though!

  • Kenwood X991 & iP200 cable with iPod 5th Gen 80GB does NOT work correctly

    I have a conundrum. My wife has the 4th Gen v1.2.1 iPod 30GB which works fine on my Kenwood X991 Head Unit. I recently purchased the "new" 80GB iPod 5th Gen with the latest version "1.0.2" which does NOT work properly. The iTunes software tells me that this 1.0.2 is the latest software.
    When I attach my iPod to my stereo, it states "Reading" for eternity. It DOES play music but only plays Alphabetical Order ONLY. There is no ability to stop, change, fast-forward, reverse, etc....the only thing you can do is click "Source" to change to CD Player or Tuner, etc...
    Does anybody out there know what is going on? I have a request into Kenwood as well. Thanks in advance for all your help!
    -Kingofbytes

    Thanks for the help. It's an iPod Classic then 80GB. The unit plays when plugged in but does not allow searching, or switching songs nor displays as it is supposed to. My wife's 30GB works with no problems. Of note:
    Her 30GB = v1.2.1
    My 80GB = 1.0.2
    Mine is newer by about 6 months. Both are the latest software according to the screen.
    Kenwood has said to "reset the head unit" and "make sure I've got it plugged in properly". I need to try the reset part next but the last statement is funny to me. I can install a head unit, amplifier, re-run all speaker wire, install a Dual 10" subwoofer box, solder and wire tie all connections from a factory unit to a 3rd party Cable manager kit, but I need to "make sure" I know how to plug in an iPod cable.....laughable.

  • Mult accounts and since I upgrade to 15 fire fox. I can not use. my family We can not open accounts with : multifox 1.3.3 does not work the second person .

    hello,
    I have 2 lab tops.. and have family members that use them.. I used to have FB open with mult family members accounts. Ad of today you updated to firefox 15..
    Now when I go to use multifox 1.3.3 ( that is so you can have mult accounts open. ) .. if trying to go into Fb none of the features work. now since I have upgrade. it use to work fine.
    So, the new FF does not work would like to unistall and go back to the old FF.. where I, can have mult accounts open at the same time and have the funcation work when your on the mult account in FB... Like talk to some one in FB chat. or just look at other items in the accounts.
    if you can tell me how to fix this or can you please give me the old link back.. or tell me how to get the old link back instead of 15.. Because 15 does not work.
    Thanks

    Install or Reinstall OS X from Scratch
    Be sure you backup your files to an external drive or second internal drive because the following procedure will remove everything from the hard drive.
    Boot to the Recovery HD:
    Restart the computer and after the chime press and hold down the COMMAND and R keys until the menu screen appears. Alternatively, restart the computer and after the chime press and hold down the OPTION key until the boot manager screen appears. Select the Recovery HD and click on the downward pointing arrow button.
    Erase the hard drive:
      1. Select Disk Utility from the main menu and click on the Continue button.
      2. After DU loads select your startup volume (usually Macintosh HD) from the
          left side list. Click on the Erase tab in the DU main window.
      3. Set the format type to Mac OS Extended (Journaled.) Optionally, click on
          the Security button and set the Zero Data option to one-pass. Click on
          the Erase button and wait until the process has completed.
      4. Quit DU and return to the main menu.
    Reinstall OS X: Select Reinstall OS X and click on the Install button.
    Note: You will need an active Internet connection. I suggest using Ethernet if possible
               because it is three times faster than wireless.

  • My ipod touch 3g with ios 5.0.1 does not work with the player's car

    ios 5.0.1 update from my ipod touch 3g does not work with various audio players Car pionerr with previous updates had not had problems like I can solve this problem???
    thanks

    I have tried everything and nothing that happened when you upgrade to ios 5.0.1, I want to know if anyone else has had this problem

  • Sync between my iPhone 4s and Mac Book Pro with OS X and iCloud does not work. Why?

    I just purchased an iPhone 4S and downloaded Mac OS X on my Mac Book Pro. Synchronization between my iPhone and my Mac Book does not work with iCloud. Why?

    You have set everything up - entered apple id, are connected to the Internet, Mac os x lion update installed enabling iCloud, etc?

  • JDK 1.6_07 with Windows: System.out.flush() does not work...

    I wonder if this is a known issue: Since I upgrade the jdk1.6 version to the _07 pack, text IO does not work anymore with WinXP cmd.exe window. Assuming a static import of System.out, I use:
    static void prompt()
      out.print(pr); //pr is a prompt string...
      out.flush();
    }works as usual with Unix/Linux, but with windows nothing will be written to the terminal, until I make at least one input. In that case a barrage of cached prompts appear all at once.
    Do we have a bug for it, can we work around somehow?
    Thomas

    Since this code works correctly in Java 6u10 on Windows XP
    System.out.print("This is the data");
    System.out.flush();You are apparently doing something unusual or wrong. What is "out"?
    Show a small sample program that compiles and exhibits the problem when executed.

  • Back and forth with two finger in folders does not work

    It is sad, that back and forth with two fingers does not work in Itunes, Folders, or somewere else than in Safari. You can put the settings back thwo three fingers but than you cannnot mark text with three fingers. It would be nice just to use two finger everywher to go back an forth

    Would be nice positive posts too ..

  • Directory Naming with OFM 11g - Identity Management Does Not Work.

    I tried to find document about how to setup/implement Directory Naming with Oracle Fusion Middleware 11g- Identity Management, but without luck. We implement Directory Naming with IM 10.1.4.3 on Linux that is 32-bit only and doesn't coexist very well with OEM GC (64-bit). So we are very eager to try 64-bit of IM 11.1.1. Any information is highly appreciated. Thanks huge.
    Edited by: bhqu888 on Aug 16, 2009 6:51 PM
    Edited by: bhqu888 on Aug 16, 2009 6:56 PM

    I installed OFM IM 11.1.1 on RHEL 4.8 (x64) successfully and OID is up and running. Using Net Manager in the $ORACLE_HOME/bin dir I can upload TNS to OID. But Directory Naming does not work. Dbs client could not log into any dbs server through this 11g OID. Our 10.1.4 OID works fine.
    Edited by: bhqu888 on Aug 16, 2009 6:51 PM
    Edited by: bhqu888 on Aug 16, 2009 6:58 PM

Maybe you are looking for