Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8528417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:47:49+00:00 2026-06-11T08:47:49+00:00

Using MVVM in Silverlight, on my View I have: <TextBox Text={Binding Path=Temperature,Mode=TwoWay} /> MyViewModel

  • 0

Using MVVM in Silverlight, on my View I have:

<TextBox Text="{Binding Path=Temperature,Mode=TwoWay}" />

MyViewModel has:

public MyModel Model {get{...}set{...}}//In my code I do have the property changed events for this
public string Temperature
{
    get
    {
        return Model.Temperature.ToString();
    }
    set
    {
        double test;
        if(double.TryParse(value, out test))
        {
            Model.Temperature = test;
        }
        else
        {
            Model.Temperature = 0D;
        }
    }
}

void Model_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
    switch(e.PropertyName)
    {
        case "Temperature":
            OnPropertyChanged("Temperature");
            break;
    }
}

MyModel has:

private double _temperature;
public double Temperature
{
    get
    {
        return _temperature;
    }
    set
    {
        _temperature = value; OnPropertyChanged("Temperature");
    }
}

If the user enters something that would not parse to a double, the Model.Temperature property gets set to 0, and I would like the TextBox to also change to 0. I thought the OnPropertyChanged events would take care of that. Any ideas whats happening?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T08:47:50+00:00Added an answer on June 11, 2026 at 8:47 am

    EDIT:
    This is caused because the Text will not call the get during the call to set. This could cause a bad infinite loop. You have a few choices.

    Delay firing property changed for the error condition:

    public string Temperature
    {
        get { return Model.Temperature.ToString(); }
        set
        {
            double test;
            if (double.TryParse(value, out test))
            {
                Model.Temperature = test;
            }
            else
            {
                Model.Temperature = 0D;
                Deployment.Current.Dispatcher.BeginInvoke(() => OnPropertyChanged("Temperature"));
            }
        }
    }
    

    Use a NumericTextBox

    Implement IDataErrorInfo on your ViewModel and set ValidatesOnDataErrors on your TextBox to true

    <TextBox Text="{Binding Temperature, Mode=TwoWay, ValidatesOnDataErrors=True}"/>
    

    OLD:
    Make sure that your binding allow for two way binding. Without it, you cannot set the TextProperty of the TextBlock.

    <TextBlock Text="{Binding Temperature, Mode=TwoWay}"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Silverlight & MVVM pattern. <TextBox Name=UserNameText Text={Binding Path=Username, Mode=TwoWay} HorizontalContentAlignment=Stretch/> In
I'm writing a Silverlight app using the MVVM pattern. I have a main view
I have a Silverlight app using mvvm with ria services. I have a textbox
I am using Silverlight 4 and the MVVM pattern. My view model has two
I am using MVVM architecture. I have a usercontrol UC as a View Model
I'm using the article Model View View-Model (MVVM) in Silverlight as a basis to
I currently have an app (in Silverlight), using mv-vm, that has an interface to
I'm creating a Silverlight 3.0 MVVM application using Silverlight.FX but my View is actually
I have a question on using MVVM within a Silverlight application I am developing.
Hi I have a silverlight MVVM application using MVVM light. When I open the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.