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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:15:57+00:00 2026-06-02T08:15:57+00:00

Why is it that if I bind two controls, say 2 TextBoxes, to a

  • 0

Why is it that if I bind two controls, say 2 TextBoxes, to a single property of a model which does not implement INotifyPropertyChanged the content of two text boxes stay in sync? How is the other TextBox being notified of the other one updating the source?

Model:

namespace BindingExample
{
    public class PersonModel
    {
        public string Name { get; set; }
    }
}

View:

<Window x:Class="BindingExample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:BindingExample"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <local:PersonModel x:Key="person"></local:PersonModel>
        <Style TargetType="TextBox">
            <Setter Property="VerticalAlignment" Value="Center" />
            <Setter Property="Width" Value="100"/>
        </Style>    
    </Window.Resources>
    <Grid DataContext="{StaticResource person}">
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <TextBox Text="{Binding Path=Name, UpdateSourceTrigger=PropertyChanged}" />
        <TextBox Grid.Row="1" Text="{Binding Path=Name, UpdateSourceTrigger=PropertyChanged}"/>
    </Grid>
</Window>
  • 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-02T08:16:00+00:00Added an answer on June 2, 2026 at 8:16 am

    The two textboxes in your example are using the same datacontext and actually share the same instance of the .NET object PersonModel, since the default setting of the static resource in the resource dictionary WPF is shared, i.e. when referencing to the static resource you will always get the same instance. More about the the x:Shared attribute on MSDN:

    MSDN article about x:Shared attribute

    An alternative to this is to set x:Shared to false to get a new instance everytime. In addition, I had to remove the binding to the datacontext in your example to individually be able to edit the values in the textboxes indivually.

    The following XAML shows this:

    <Window x:Class="WpfScrollToEndBehavior.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:WpfScrollToEndBehavior"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <local:PersonModel x:Key="person" x:Shared="false" Name="John Doe"> </local:PersonModel>
        <Style TargetType="TextBox">
            <Setter Property="VerticalAlignment" Value="Center" />
            <Setter Property="Width" Value="100"/>
        </Style>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <TextBox Text="{Binding Path=Name, UpdateSourceTrigger=PropertyChanged, Source={StaticResource person}}" />
        <TextBox Grid.Row="1" Text="{Binding Path=Name, UpdateSourceTrigger=PropertyChanged, Source={StaticResource person}}" />
    </Grid>
    

    The reason for x:Shared is set to true for resources in a resource dictionary is for efficiency reasons. By setting x:Shared on a resource (e.g. an object) in a resource dictionary in XAML will give us new instances everytime the resource is references and accessed. I had to remove the data context from the grid and set the source of the binding for the textboxes to the static resource person.

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

Sidebar

Related Questions

I have the same command that I want to use for two controls on
I have a form that is bind to an object, and when the user
I have an anonymous linq query that I bind to a datagrid, when I
I have a set of list items in unordered lists that I bind the
I was certain that if you bind a buffer via glBindBuffer() , you can
I noticed the other day that I cannot bind variables when using PDO with
I've an ASP.Net 2.0 Gridview control that I can bind a List<T> too, for
I am trying to bind an image that is saved in isolated storage and
It turns out that in order to do this one has to bind the
I'm trying to bind a XAML ComboBox so that its list items are the

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.