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

  • Home
  • SEARCH
  • 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 8030919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:55:27+00:00 2026-06-05T00:55:27+00:00

I have a WPF view with a TextBox, binding the Text field to a

  • 0

I have a WPF view with a TextBox, binding the Text field to a ViewModel with UpdateSourceTrigger set to PropertyChanged. In the property setter in the ViewModel, I have a simple check to prevent the text from exceeding 10 characters:

<TextBox Text="{Binding Name, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();

        this.DataContext = new MainViewModel();
    }
}


public string Name
{
    get { return _Name; }
    set
    {
        if (_Name != value)
        {
            if (value.Length <= 10)
            {
                _Name = value;
            }
            RaisePropertyChanged("Name");
        }
    }
}

If the value isn’t set, I still RaisePropertyChanged (which simply fires PropertyChanged).

The problem is that when I type in the 11th character in the UI, I don’t update _Name. I fire PropertyChanged, and I can see the get accessor get called and it returns the string with only 10 characters. However, my TextBox doesn’t reflect this; it still shows the string with 11 characters.

On top of that, is that if on the 11th character I change the text in the setter to “ERROR”, and fire property changed, the TextBox DOES update to show the altered text.

So why is it that if I alter the text in the setter back to the previous value, the UI doesn’t reflect this?

I know there are alternative ways of handling max characters, but why won’t this work?

  • 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-05T00:55:28+00:00Added an answer on June 5, 2026 at 12:55 am

    This is nothing but a bug in the framework. The Text property in the TextBox does get your new value but the GUI is now out of sync with its own TextProperty. This also happends for any ItemsControl when you want to cancel a change of SelectedItem from the ViewModel and it’s really annoying.

    This bug doesn’t happend when you use explicit Binding though so this can be used as a workaround.

    Xaml

    <TextBox Text="{Binding Path=MyName,
                            UpdateSourceTrigger=Explicit}"
             TextChanged="TextBox_TextChanged"/>
    

    Code behind

    private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
    {
        TextBox textBox = sender as TextBox;
        textBox.GetBindingExpression(TextBox.TextProperty).UpdateSource();
    }
    

    To verify that the TextBox GUI indeed is out of sync, just observe the value of TextBox.Text. The TextBox will say “123456789___0” for example while TextBlock says “123456789”.

    <StackPanel>
        <TextBox Name="myTextBox"
                 Text="{Binding Path=MyName,
                                UpdateSourceTrigger=PropertyChanged}"/>
        <TextBlock Text="{Binding ElementName=myTextBox, Path=Text}"/>
    </StackPanel>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my WPF application I have a View that is given a ViewModel, and
In a WPF application I have a ListView: <ListView Name=ItemSelList ItemsSource={Binding ItemColl} SelectionChanged=ItemSelList_SelectionChanged> <ListView.View>
Simple WPF question I have a text Box and an OK Button and I
I have a WPF view\view-model binding pattern where I would like to resolve dependencies
I have a WPF-View with an ItemsControl that binds an ObservableCollection from the ViewModel.
I have a WPF ComboBox which has its IsEditable property bound to a view
I'm writing an application using WPF MVVM. I have a view model with property
I have a WPF view that displays a Shipment entity. I have a textblock
I have used a list view that uses a grid view in WPF. I
I have a WPF page (as my View) in an MVVM model. The View

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.