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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:47:49+00:00 2026-05-18T02:47:49+00:00

The line below works for the TextBox DP Text , where CellNo is a

  • 0

The line below works for the TextBox DP Text, where CellNo is a property of a class which derives from INotifyPropertychanged. So here when I change the CellNo the Text will be updated and When I change the CellNo the Text will be updated. This will work fine.

Text="{Binding Path = CellNo, Mode=TwoWay,  UpdateSourceTrigger=PropertyChanged}"

I have create a user control which contain only one TextBox. I have defined one DP name CellValue as below:

public string CellValue
    {
        get { return (string)GetValue(CellValueProperty); }
        set { SetValue(CellValueProperty, value); }
    }

    // Using a DependencyProperty as the backing store for LimitValue.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty CellValueProperty =
        DependencyProperty.Register("CellValue", typeof(string), typeof(control), new FrameworkPropertyMetadata
        {
            BindsTwoWayByDefault = true,
        });

Now when I use this user control in any dialog and do the same binding as above, the Target ( TextBox inside User control) is NOT updating.

 <local:control
        x:Name="control" 
        CellValue="{Binding Path = CellNo, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">

Also inside user control I have binded the Text Property of TextBox to CellValue DP.

Inside User control

<TextBox                 
        Text="{Binding Path = CellValue}"
        Name="textBox2" />

I want when the CellValue changes the TextBox Text should also be updated, but with the above appoach it remains blank.

  • 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-05-18T02:47:49+00:00Added an answer on May 18, 2026 at 2:47 am

    This code

    <local:control x:Name="control"  
                   CellValue="{Binding Path=CellNo,
                                       Mode=TwoWay,
                                       UpdateSourceTrigger=PropertyChanged}">
    

    is trying to bind against the Property CellNo of the UserControl. Add RelativeSource or ElementName and it’ll work.

    <local:control x:Name="control"  
                   CellValue="{Binding Path=CellNo,
                                       RelativeSource={RelativeSource AncestorType={x:Type Window}}, 
                                       Mode=TwoWay,
                                       UpdateSourceTrigger=PropertyChanged}">
    
    <local:control x:Name="control"  
                   CellValue="{Binding Path=CellNo,
                                       ElementName=myWindow,
                                       Mode=TwoWay,
                                       UpdateSourceTrigger=PropertyChanged}">
    

    You may also need to set the the DataContext of control to itself

    public control()
    {
        InitializeComponent();
        this.DataContext = this;
        //...
    }
    

    Update

    You can download a sample application of this here.

    Otherwise, here’s my full sample code.

    MainWindow.xaml

    <Window x:Class="DependencyPropertyInsideUserControl.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:local="clr-namespace:DependencyPropertyInsideUserControl"
            Title="MainWindow" Height="350" Width="525"
            Name="myWindow">
        <Grid>
            <local:control x:Name="control"
                           CellValue="{Binding Path = CellNo, Mode=TwoWay, ElementName=myWindow, UpdateSourceTrigger=PropertyChanged}"/>
                <Button Content="Update CellNo" Height="23" HorizontalAlignment="Left" Margin="185,149,0,0" Name="button1" VerticalAlignment="Top" Width="94" Click="button1_Click" />
        </Grid>
    </Window>
    

    Mainwindow.xaml.cs

    public partial class MainWindow : Window, INotifyPropertyChanged
    {
        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = this;
            CellNo = "Hello";
        }
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            CellNo = "Hi";
        }
        private string m_cellNo;
        public string CellNo
        {
            get
            {
                return m_cellNo;
            }
            set
            {
                m_cellNo = value;
                OnPropertyChanged("CellNo");
            }
        }
        public event PropertyChangedEventHandler PropertyChanged;
        private void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
    

    control.xaml

    <UserControl x:Class="DependencyPropertyInsideUserControl.control"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                 mc:Ignorable="d" 
                 d:DesignHeight="300" d:DesignWidth="300">
        <Grid>
            <TextBox Text="{Binding Path = CellValue}" 
                     Name="textBox2" />
        </Grid>
    </UserControl>
    

    control.xaml.cs

    public partial class control : UserControl
    {
        public string CellValue
        {
            get { return (string)GetValue(CellValueProperty); }
            set { SetValue(CellValueProperty, value); }
        }
        // Using a DependencyProperty as the backing store for LimitValue.  This enables animation, styling, binding, etc...    
        public static readonly DependencyProperty CellValueProperty =
            DependencyProperty.Register("CellValue", typeof(string), typeof(control), new FrameworkPropertyMetadata
            {
                BindsTwoWayByDefault = true,
            });
        public control()
        {
            InitializeComponent();
            this.DataContext = this;
            CellValue = "Test";
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The code below works. But if I comment out the line Dim objRequest As
At the XmlSerializer constructor line the below causes an InvalidOperationException which also complains about
currently i obtain the below result from the following C# line of code when
How do I change the height of a textbox ? Neither of the below
I have a few places where I use the line below to clear out
As of now I'm using below line to print with out dot's fprintf( stdout,
I'm getting the following error on the line of code below: Syntax error (missing
How would I accomplish displaying a line as the one below in a console
I'm calling the code below. On the line (IDataReader dr = cmd.ExecuteReader()) sql barfs
Line of code is: BreakDown(Full As String, FName As String, PName As String, Ext

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.