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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:06:44+00:00 2026-06-07T11:06:44+00:00

My UserControl contains a TextBox and a Button. The TextBox’s Text is correctly populated

  • 0

My UserControl contains a TextBox and a Button. The TextBox’s Text is correctly populated by a dependency property called X.

My Goal:
Change the value of X (e.g. Text of the TextBox) when I press the Button.

I have defined the UserControl as follows:

<StackPanel Orientation="Horizontal" >
    <TextBox Name="Xbox" Text="{Binding Path=X}" Width="50"/>
    <Button Content="Current" Click="InsertCurrentBtnClick" />
</StackPanel>

With codebehind:

    public double X
    {
        get { return (double)GetValue(XProperty); }
        set { SetValue(XProperty, value); }
    }

    public static readonly DependencyProperty XProperty =
        DependencyProperty.Register("X", typeof(double), typeof(MyUserControl), new PropertyMetadata(0.0));


    private void InsertCurrentBtnClick(object sender, RoutedEventArgs e)
    {
        X = 0.7;

        //BindingOperations.GetBindingExpression(this, XProperty).UpdateTarget();
        //BindingOperations.GetBindingExpression(Xbox, TextBox.TextProperty).UpdateTarget();
        //BindingOperations.GetBindingExpression(Xbox, XProperty).UpdateTarget();
        //Xbox.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
        //GetBindingExpression(XProperty).UpdateTarget();
    }

I have tried several things – one at a time – (see below X=0.7;) to force the update to the TextBox Text but nothing has helped so far.

Thanks in advance.

  • 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-07T11:06:45+00:00Added an answer on June 7, 2026 at 11:06 am

    I’d write it in this way:

        public double X
        {
            get { return (double)GetValue(XProperty); }
            set { SetValue(XProperty, value); }
        }
    
        public static readonly DependencyProperty XProperty =
            DependencyProperty.Register("X", typeof(double), typeof(MainPage), new PropertyMetadata(new PropertyChangedCallback(Callback)));
    
    
        public static void Callback(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            (o as MainPage).Xbox.Text = e.NewValue.ToString();
        }
    
        private void InsertCurrentBtnClick(object sender, RoutedEventArgs e)
        {
            X = 0.7;
        }
    

    And the xaml code:

        <StackPanel Orientation="Horizontal" >
            <TextBox Name="Xbox" Width="50"/>
            <Button Content="Current" Click="InsertCurrentBtnClick" />
        </StackPanel>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UserControl that contains a TextBox. The TextBox.Text property is data-bound and
I'm writing a user control with a dependency property for a search text called
I have UserControl which contains a TextBox and a Button control. The Button opens
I have a UserControl which contains a TextBox . When my main window loads
I have an UserControl that contains a Button : <UserControl> <Button> </UserControl> I want
I've created a WPF UserControl which contains a Button. I now want any consumer
I have a UserControl and it contains a Button . Now, in some Windows
I have a UserControl which contains a TextBox and a CustomValidator. I would like
My WPF UserControl contains two stack panels and each of them contains labels, text
I created a UserControl that contains a textbox . When I try to initialize

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.