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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:06:24+00:00 2026-05-29T16:06:24+00:00

i have encountered a databinding probleme, so i create a usercontrole UserControl1.xaml.cs public partial

  • 0

i have encountered a databinding probleme,
so i create a usercontrole

UserControl1.xaml.cs

public partial class UserControl1 : UserControl
{
    public UserControl1()
    {
        InitializeComponent();
    }
    public static DependencyProperty TestThisProperty = DependencyProperty.Register
        (
        "TestThis",
        typeof(string),
        typeof(UserControl1),
        new PropertyMetadata("Some Data",new PropertyChangedCallback(textChangedCallBack))
        );
    public string TestThis
    {
        get { return (string)GetValue(TestThisProperty); }
        set { SetValue(TestThisProperty, value); }
    }
    static void textChangedCallBack(DependencyObject property, DependencyPropertyChangedEventArgs args)
    {
        UserControl1 _us = (UserControl1)property;

        _us.MyUserControl.TestThis = (string)args.NewValue;

    }
}

UserControl1.xaml

<UserControl x:Class="WpfApplication1.UserControl1"
         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"  x:Name="MyUserControl"

         d:DesignHeight="300" d:DesignWidth="300">
          </UserControl>

MainWindow.xaml.cs

public partial class MainWindow : Window
{
    UserControl1 _uc = new UserControl1();

    public MainWindow()
    {
        InitializeComponent();
        DispatcherTimer _dt = new DispatcherTimer();
        _dt.Interval = new TimeSpan(0, 0, 1);
        _dt.Start();
        _dt.Tick += new EventHandler(_dt_Tick);
    }
    private void _dt_Tick(object s,EventArgs e)
    {
        _uc.TestThis = DateTime.Now.ToString("hh:mm:ss");

    }

and finaly the MainWindow.xaml

<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:WpfApplication1"
    Title="MainWindow" Height="350" Width="525">

<Grid>
    <TextBox Text="{Binding Path=TestThis,ElementName=MyUserControl, UpdateSourceTrigger=PropertyChanged}"/>

  </Grid>

but the problem here, whene i debug my code i get this warning
Cannot find source for binding with reference ‘ElementName=MyUserControl’. and the ui does not update of course,any idea please?

  • 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-29T16:06:25+00:00Added an answer on May 29, 2026 at 4:06 pm

    ElementName only targets names in the same namescope, e.g.

    <TextBox Name="tb"/>
    <Button Content="{Binding Text, ElementName=tb}"/>
    

    If you do not define the UserControl in the MainWindow XAML and give it a name there or register a name in code behind (and target that) you won’t get this ElementName binding to work.

    An alternative would be exposing the usercontrol as a property on the MainWindow, e.g.

    public UserControl1 UC { get { return _uc; } }
    

    Then you can bind like this:

    {Binding UC.TestThis, RelativeSource={RelativeSource AncestorType=Window}}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have encountered a very strange class not found problem in our web app
I have encountered this error Fatal error: Class 'PHPExcel_Shared_ZipStreamWrapper' not found in \VBOXSVR\ACACIASOFT\apc\spreadsheet\lib\phpexcel\PHPExcel\Autoloader.php on
I have encountered a strange behavior with a simple C++ class. classA.h class A
I have encountered a most annoying problem that occurs on the PWD variable when
I have encountered a rather nasty problem with the DataGridView control (Windows.Forms, .NET Framework
I have encountered a problem twice now whereby a producer thread produces N work
I have encountered a problem of placing data into the Table View. Here is
I have encountered a weird situation while updating/upgrading some legacy code. I have a
I have encountered a problem in my application. I have two forms, one that
I have encountered this topic lately and couldn't understand why they are needed. Can

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.