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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:52:18+00:00 2026-06-17T17:52:18+00:00

I have a: System.Windows.Data Error: 4 : Cannot find source for binding with reference

  • 0

I have a:

System.Windows.Data Error: 4 : Cannot find source for binding with
reference ‘ElementName=Test’. BindingExpression:Path=Value;
DataItem=null; target element is ‘Slider’ (Name=”); target property
is ‘Value’ (type ‘Double’)

error in a very special case.
I though about a name scope problem but I don’t know how to fix it.

Consider the following WPF application :

MyUserControl.xaml:

<UserControl x:Class="WpfApplication1.MyUserControl"
             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>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <Label Grid.Row="0" Content="Move me !"/>
        <Slider x:Name="Test" Grid.Row="0" Grid.Column="1" />
        <Label Grid.Row="1" Content="Binded slider"/>
        <ContentPresenter Grid.Row="1" Grid.Column="1">
            <ContentPresenter.Content>
                <Slider Value="{Binding Value, ElementName=Test}"/>
            </ContentPresenter.Content>
        </ContentPresenter>
    </Grid>
</UserControl>

MyUserControl.xaml.cs:

using System.Windows.Controls;

namespace WpfApplication1
{
    public partial class MyUserControl : UserControl
    {
        public MyUserControl()
        {
            InitializeComponent();
        }
    }
}

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" Title="MainWindow" Width="300" Height="120">

    <StackPanel>
        <Button Click="Button_Click" Content="Click me to show Sliders !" Height="25"/>
        <ContentPresenter x:Name="contentPresenter"/>
    </StackPanel>
</Window>

MainWindow.xaml.cs:

using System.Windows;

namespace WpfApplication1
{
    public partial class MainWindow : Window
    {
        private MyUserControl myUserControl;

        public MainWindow()
        {
            InitializeComponent();

            myUserControl = new MyUserControl();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            contentPresenter.Content = myUserControl;
        }
    }
}

Given the code of MyUserControl.xaml, I expect the binded slider to have the same value has the first one.

But nothing happens.

Now, the tricky part: Start the application, Click on the button, Move the first slider, Open “WPF Inspector” and Attach it to the application. Result: The binding is fixed.

How do you explain this phenomenon?

  • 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-17T17:52:20+00:00Added an answer on June 17, 2026 at 5:52 pm

    This will do the trick

        <!--<ContentPresenter Grid.Row="1" Grid.Column="1">
            <ContentPresenter.Content>-->
                <Slider Value="{Binding Value, ElementName=Test}" Grid.Column="1" Grid.Row="1"/>
            <!--</ContentPresenter.Content>
        </ContentPresenter>-->
    

    Because Slider is inside a content presenter you can’t access it’s value like that. You would need to bind to the same viewmodel property to achive this while having it in the content presenter.

    Edit

    Get Prism and user a ViewModel… I won’t go into details… But What you need to do is this…

    After you donwloaded everything add the Microsoft.Practices.Prism dll to your project

    Create a new class (ViewModel).Name it whatever you want. I call my MyUserControlViewModel and make it look like this

    using Microsoft.Practices.Prism.ViewModel;
    
    namespace YourNamespace
    {
        public class MyUserControlViewModel : NotificationObject
        {
            private double _sliderValue;
    
            public double SliderValue
            {
                get { return _sliderValue; }
                set
                {
                    _sliderValue = value;
                    RaisePropertyChanged(() => SliderValue);
                }
            }
    
        }
    }
    

    Change the XAML in your usercontrol like this

    <Slider x:Name="Test" Grid.Row="0" Grid.Column="1" Value="{Binding SliderValue, Mode=TwoWay}"/>        
    <ContentPresenter Grid.Row="1" Grid.Column="1">
        <ContentPresenter.Content>
            <Slider Value="{Binding SliderValue}"/>
        </ContentPresenter.Content>
    </ContentPresenter>
    

    And add this line of code into your MyUserControl.cs file

    DataContext = new MyUserControlViewModel();
    

    Now the ViewModel takes over for the heavy lifting… You bound the value of the first slider to the Property SliderValue (the Mode=TwoWay indicates that this control can set and get the state of the property) and you have bound the other slider to the same SliderValue so that it moves in sync with the first

    Hope this helps

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

Sidebar

Related Questions

I am getting the error: System.Windows.Data Error: 4 : Cannot find source for binding
I have a System.Windows.Forms.ComboBox on a form and I want to capture the event
I have a System.Windows.Forms.Button control, and I want to add a hover-text explanation of
I have a System.Windows.Forms.PropertyGrid with different types of values. For a specific item, I
How do I send a period using sendkeys? I have tried: System.Windows.Forms.SendKeys.SendWait({.}); System.Windows.Forms.SendKeys.SendWait(.); but
I have a control ...any System.Windows.Forms.Control . say for eg. label. I wish to
I have a form MyForm : System.Windows.Forms.Form {} and I need to call Site.GetService(..)
I have an application where the System.Windows.Forms.ColorDialog dialog box is used as a color
The Application class in System.Windows.Forms have a some properties that can be quite useful.
I have my own textbox which inherits System.Windows.Forms.TextBox I am trying to display texts

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.