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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:34:57+00:00 2026-06-15T12:34:57+00:00

I have a TextBox and I’m trying to bind it to a DependencyProperty .

  • 0

I have a TextBox and I’m trying to bind it to a DependencyProperty. The property is never touched on load or when I type in the TextBox. What am I missing?

XAML

<UserControl:Class="TestBinding.UsernameBox"
        // removed xmlns stuff here for clarity>
    <Grid>
        <TextBox Height="23" Name="usernameTextBox" Text="{Binding Path=Username, ElementName=myWindow, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />
    </Grid>
</UserControl>

C#

public partial class UsernameBox : UserControl
{
    public UsernameBox()
    {
        InitializeComponent();
    }

    public string Username
    {
        get
        {
            // Control never reaches here
            return (string)GetValue(UsernameProperty);
        }
        set
        {
            // Control never reaches here
            SetValue(UsernameProperty, value);
        }
    }

    public static readonly DependencyProperty UsernameProperty
        = DependencyProperty.Register("Username", typeof(string), typeof(MainWindow));
}

Edit: I need to implement a DependencyProperty because I am creating my own control.

  • 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-15T12:34:58+00:00Added an answer on June 15, 2026 at 12:34 pm

    You never reach setter because it is CLR wrapper of dependency property, it is declared to be set from external sources, like mainWindow.Username = "myuserName";. When the property is set through binding and you want to see if it changed or not just add the PropertyMetadata to your declaration with PropertyChangedCallback, for example:

    public static readonly DependencyProperty UsernameProperty =
                DependencyProperty.Register("Username", typeof(string), typeof(MainWindow), new UIPropertyMetadata(string.Empty, UsernamePropertyChangedCallback));
    
            private static void UsernamePropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
            {
                Debug.Print("OldValue: {0}", e.OldValue);
                Debug.Print("NewValue: {0}", e.NewValue);
            }
    

    With this code you will see changes of your property in Output Window of VS.

    For more info on callbacks please read Dependency Property Callbacks and Validation

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have textbox on our MVC view. Once we load data, we are unable
I have usercontrol called as 'DateControl1' in which i have textbox and a calenderextender(ajax).I
i have a textbox which is determining the time, on the form load i
I am trying to implement data binding, and to have TextBox's text to be
I have a TextBox bound to a ViewModel's Text property with the following setup:
i have the following datatemplate in xaml and here i have textbox in datatemplate
I have a textbox whose input is being handled by jQuery. $('input.Search').bind(keyup, updateSearchTextbox); When
I have a textbox with the Text property bound to a dataset column with
I have textbox in xaml <TextBlock Style={StaticResource PhoneTextExtraLargeStyle} FontSize={StaticResource PhoneFontSizeLarge} FontFamily={StaticResource PhoneFontFamilySemiLight} Margin=12,10,12,0 />
I have Textbox with blue Background and white Foreground . When entering a text

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.