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 8534811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:16:58+00:00 2026-06-11T10:16:58+00:00

Some days ago I realized that in Silverlight, in order to always update the

  • 0

Some days ago I realized that in Silverlight, in order to always update the bindings on any texbox (in order to validate for error in each KeyPress) I needed this code on TextChanged Event event in every TextBox I had in the system:

TextBox txCtl = (TextBox)sender; if (txCtl != null)
{
    var be = txCtl.GetBindingExpression(TextBox.TextProperty);

    if (be != null)
    {
        be.UpdateSource();
    }
}

This code works pretty well (source: http://forums.silverlight.net/t/51100.aspx/1). The problem is: I don’t want to repeat it in every view CodeBehind I have, so I decided to make a custom ViewBase where I would leave this code on it. What I did was simply:

public class ViewBase : ChildWindow
{
    protected void tboxTextChanged(object sender, TextChangedEventArgs e)
    {
        TextBox txCtl = (TextBox)sender; if (txCtl != null)
        {
            var be = txCtl.GetBindingExpression(TextBox.TextProperty);

            if (be != null)
            {
                be.UpdateSource();
            }
        }
    }
}

And then my view now is a ViewBase, instead of a UserControl, so I also changed the XAML to:

<src:ViewBase x:Class="Oi.SCPOBU.Silverlight.Pages.CadastroClassificacao"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:src="clr-namespace:Oi.SCPOBU.Silverlight.Pages" [...]

Finally, in my textbox I left the event referencing the same method as usual, but now the method is in ViewBase, istead of being in the CodeBehind:

<TextBox
   x:Name="tbxNome"
   Width="300"
   MaxLength="50"
   HorizontalAlignment="Left"
   TextChanged="tboxTextChanged"
   Text="{Binding DTOClassificacao.Nome, Mode=TwoWay, NotifyOnValidationError=True>

Seems pretty straightforward to me, but this doesn’t work. The code compiles, but in runtime I get the error: “Message=Failed to assign to property ‘System.Windows.Controls.TextBox.TextChanged’. [Line: 43 Position: 37]”, on the InitializeComponent() Method.

Anybody knows how can I assign a method from my base class to an event? Or will I really have to repeat this code in every single View I have?

  • 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-11T10:16:59+00:00Added an answer on June 11, 2026 at 10:16 am

    in order to always update the bindings on any texbox (in order to
    validate for error in each KeyPress) I needed this code on TextChanged
    Event event in every TextBox I had in the system

    Have you tried UpdateSourceTrigger.PropertyChanged?

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

Sidebar

Related Questions

Some days ago I realized that PrintWriter (as well as PrintStream ) never throw
Some days ago, I decided that it would be fun to write a streambuf
Based on my question posted a few days ago, I realized that SimpleFormController is
Some days ago I installed the ASP.NET MVC 3 Tools Update for Visual Studio
I had a similar question some days ago that was solved, but now, some
Some days ago I run into a severe problem that gives me a headache:
Some days ago I asked a question about tagging differencies in 2 text files,
Some days ago I started using partitioning to make it possible to work with
Some days ago I looked at boost sources and found interesting typedef . There
Some days ago I found a great project: vs-android. It allows you to build

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.