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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:39:39+00:00 2026-06-10T16:39:39+00:00

I have the following controls embedding (not inheritance, just placing): Native TextBlock is placed

  • 0

I have the following controls embedding (not inheritance, just placing):
enter image description here

Native TextBlock is placed in MyMiddleControl, which is placed in MyGlobalControl.
MyMiddleControl has a DependencyPropery “GroupName”, which is binded to TextBox.Text.
MyGlobalControl has a public property “MyText, which is binded to MyMiddleControl.GroupName.

XAML:

<UserControl x:Class="MyMiddleControl"
         ...
         DataContext="{Binding RelativeSource={RelativeSource Mode=Self}}">
    <TextBlock Text="{Binding Path=GroupName}"/>
</UserControl>

with

public static readonly DependencyProperty GroupNameProperty =
    DependencyProperty.Register("GroupName", typeof(string), 
    typeof(MyMiddleControl), 
    new PropertyMetadata("default"));

public string GroupName
{
    get { return (string)GetValue(GroupNameProperty); }
    set { SetValue(GroupNameProperty, value); }
}

and

<UserControl x:Class="MyGlobalControl"
         ...
         DataContext="{Binding RelativeSource={RelativeSource Mode=Self}}">
    <MyMiddleControl GroupName="{Binding MyText}"... />
</UserControl>

with

public string _myText = "myDef";
public string MyText
{
    get { return _myText ; }
    set { _myText = value; }
}

Problem #1. When I run the program I see “default” in the textblock instead of “myDef”.

Problem #2. I have the button which do:

private void TestButton_Click(object sender, RoutedEventArgs e)
{
    MyText = "TestClick";
}

The result is the same: “default”.

Why? 🙁

Update:

I forget to say. If I do

<UserControl x:Class="MyGlobalControl"
         ...
         DataContext="{Binding RelativeSource={RelativeSource Mode=Self}}">
    <MyMiddleControl GroupName="FixedTest"... />
</UserControl>

It works fine.

PS. The sample project with changes from the first answer: TestBind.zip.

  • 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-10T16:39:41+00:00Added an answer on June 10, 2026 at 4:39 pm

    you must implement INotifyPropertyChanged to notify changes for a binded property

    public class SampleData : INotifyPropertyChanged
    {
      public SampleData ()
      {
         this.MyText = "myDef";
      }
    
      public string _myText;
      public string MyText
      {
        get { return _myText ; }
        set {
          _myText = value;
          this.RaisePropChanged("MyText");
        }
      }
    
      public event PropertyChangedEventHandler PropertyChanged;
    
      public void RaisePropChanged(string name) {
        var eh = this.PropertyChanged;
        if (eh != null) {
          eh(this, new PropertyChangedEventArgs(name));
        }
      }
    }
    

    hope that helps

    EDIT
    try following solution with setting x:Name and DataContext in code behind

    public partial class MyMiddleControl : UserControl
    {
      public MyMiddleControl() {
        this.DataContext = this;
        this.InitializeComponent();
      }
    
      public static readonly DependencyProperty GroupNameProperty =
        DependencyProperty.Register("GroupName", typeof(string),
                                    typeof(MyMiddleControl),
                                    new PropertyMetadata("default"));
    
      public string GroupName {
        get { return (string)this.GetValue(GroupNameProperty); }
        set { this.SetValue(GroupNameProperty, value); }
      }
    }
    
    <UserControl x:Class="TestBind.MyMiddleControl"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 x:Name="middleControl">
        <Grid>
            <TextBlock Height="40" HorizontalAlignment="Left" Margin="45,23,0,0" 
                       Name="textBlock1" Text="{Binding ElementName=middleControl, Path=GroupName}" 
                       VerticalAlignment="Top" Width="203" />
        </Grid>
    </UserControl>
    
    public partial class MyGlobalControl : UserControl, INotifyPropertyChanged
    {
      public MyGlobalControl() {
        this.DataContext = this;
        this.InitializeComponent();
        this.MyText = "myDef";
      }
    
      public string _myText;
      public string MyText {
        get { return this._myText; }
        set {
          this._myText = value;
          this.OnPropertyChanged("MyText");
        }
      }
    
      public event PropertyChangedEventHandler PropertyChanged;
    
      protected virtual void OnPropertyChanged(string propertyName) {
        PropertyChangedEventHandler handler = this.PropertyChanged;
        if (handler != null) {
          handler(this, new PropertyChangedEventArgs(propertyName));
        }
      }
    
      private void button1_Click(object sender, RoutedEventArgs e) {
        this.MyText = "btnClick";
      }
    }
    
    <UserControl x:Class="TestBind.MyGlobalControl"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:my="clr-namespace:TestBind"
                 x:Name="globalControl">
      <Grid>
        <my:MyMiddleControl HorizontalAlignment="Left"
                            Margin="24,82,0,0"
                            x:Name="myFloatTest"
                            GroupName="{Binding ElementName=globalControl, Path=MyText}"
                            VerticalAlignment="Top" />
        <Button Content="Button"
                Height="23"
                HorizontalAlignment="Left"
                Margin="296,65,0,0"
                Name="button1"
                VerticalAlignment="Top"
                Width="75"
                Click="button1_Click" />
      </Grid>
    </UserControl>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code that just has controls relating to an item. <ul
I have the following functions which controls the opacity property of four images with
I am trying a sample application in which I have taken following controls: i.
I have the following Javascript code which controls an accordion type set of divs.
I have a RadAjaxPanel which contains the following controls: RadTabStrip RadMultiPage The RadMultiPage consists
I have the following trackbar controls which I have added to a tabpage 'tab1':
I have the following controls: <UserControl > <!--<ScrollViewer >--> <Viewbox > <Canvas/> </Viewbox> <!--</ScrollViewer>-->
I have the following code that controls the presentation of an interdependent group. The
I have the following code: foreach (var control in this.Controls) { } I want
I have the following XAML: <UserControl x:Class=EMS.Controls.Dictionary.TOCControl xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:vm=clr-namespace:EMS.Controls.Dictionary.Models xmlns:diagnostics=clr-namespace:System.Diagnostics;assembly=WindowsBase x:Name=root > <TreeView

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.