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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:13:27+00:00 2026-05-27T15:13:27+00:00

I have two controls on WPF <Button HorizontalAlignment="Center" Name="btnChange" Click="btnChange_Click" Content="Click Me" /> <Label

  • 0

I have two controls on WPF

<Button HorizontalAlignment="Center"
        Name="btnChange"
        Click="btnChange_Click"
        Content="Click Me" />

<Label Name="lblCompanyId"
       HorizontalAlignment="Center"
       DataContext="{Binding ElementName=_this}"
       Content="{Binding Path=CompanyName}" />

As we can see that label is bound to local property(in code Behind), I don’t see any value on label when I click button…

Below is my code behind…

public static readonly DependencyProperty CompanyNameProperty =
  DependencyProperty.Register("CompanyName", typeof(string), typeof(Window3), new UIPropertyMetadata(string.Empty));

public string CompanyName {
  get { return (string)this.GetValue(CompanyNameProperty); }
  set { this.SetValue(CompanyNameProperty, value); }
}

private void btnChange_Click(object sender, RoutedEventArgs e) {
  this.CompanyName = "This is new company from code beind";
}
  • 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-27T15:13:28+00:00Added an answer on May 27, 2026 at 3:13 pm

    Try:

    Content="{Binding ElementName=_this, Path=CompanyName}"
    

    Without the DataContext binding.

    EDIT

    I have no problems with your code, have named your window to x:Name="_this"?

    <Window x:Class="WpfStackOverflowSpielWiese.Window3"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="Window3"
            Height="300"
            Width="300"
            x:Name="_this">
      <Grid>
        <StackPanel>
          <Button HorizontalAlignment="Center"
                  Name="btnChange"
                  Click="btnChange_Click"
                  Content="Click Me" />
    
          <Label Name="lblCompanyId"
                 HorizontalAlignment="Center"
                 DataContext="{Binding ElementName=_this}"
                 Content="{Binding Path=CompanyName}"></Label>
    
        </StackPanel>
      </Grid>
    </Window>
    

    Is your window really Window3?

    public partial class Window3 : Window
    {
      public Window3() {
        this.InitializeComponent();
      }
    
      public static readonly DependencyProperty CompanyNameProperty =
        DependencyProperty.Register("CompanyName", typeof(string), typeof(Window3), new UIPropertyMetadata(string.Empty));
    
      public string CompanyName {
        get { return (string)this.GetValue(CompanyNameProperty); }
        set { this.SetValue(CompanyNameProperty, value); }
      }
    
      private void btnChange_Click(object sender, RoutedEventArgs e) {
        this.CompanyName = "This is new company from code behind";
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a window (Windows form ) where i have two WPF user controls
I have simple Windows Forms application (not WPF), and I have two controls on
I have a data class that implements INotifyPropertyChanged and two WPF controls that DataBind
I have two simple custom controls derived from standard WPF controls. I.e. internal class
I have two controls on a page, one is a search entry and submission
In Winforms you can have two controls tied to the same datasource in a
I am using standard windows forms controls under C#. I have two controls which
I have two custom controls that are analogous to a node and the control
I have two TDBLookupComboBox controls that I'd like to connect to the same dataset,
I've got a form where I have two radio buttons and two interchangeable controls

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.