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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:09:49+00:00 2026-06-13T09:09:49+00:00

I have a simple binding question as I feel I’m missing something fundamental in

  • 0

I have a simple binding question as I feel I’m missing something fundamental in my view of how binding works.

I assume that since I’ve set the DataContext of my MainWindow to a ViewModel in code-behind, that all of the binding in MainWindow.xaml would assume source of this DataContext unless otherwise specified. This does not seem to be the case when I’m using my UserControl (which itself has a ViewModel driving it)

My scenario is best described in code:

MainWindow.xaml.cs

private ViewModels.MainMenuViewModel vm;

public MainWindow()
{
    InitializeComponent();

    vm = new ViewModels.MainMenuViewModel();
    this.DataContext = vm;
}

MainWindow.xaml (using the data-context set in code-behind)

x:Class="Mediafour.Machine.EditorWPF.Views.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:uc="clr-namespace:Machine.EditorWPF.Views"
xmlns:local="clr-namespace:Machine.EditorWPF"
xmlns:localVM="clr-namespace:Machine.EditorWPF.ViewModels"
Title="MainWindow" Height="350" Width="650">



  <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="auto"/>
        </Grid.ColumnDefinitions>
        <uc:MachineTreeView x:Name="MachineTreeView" Grid.Column="0" MachineDocument="{Binding Path=CurrentDocument}" />

MainWindowViewModel.cs

 public class MainWindowViewModel : ObservableObject
    {
       public MainWindowViewModel()
        {
            OpenMachine(@"D:\Projects\Agnes\EditorWPF\Test.machine");
        }

        private void OpenMachine(string filePath)
        {
            MachineDocument currentDocument = MachineDocument.OpenFile(filePath);
            CurrentDocument = currentDocument;
        }

        private MachineDocument _currentDocument;
        public MachineDocument CurrentDocument
        {
            get { return _currentDocument; }
            set
            {
                if (_currentDocument != null)
                {
                    _currentDocument.Dispose();
                    _currentDocument = null;
                }

                _currentDocument = value;
                base.RaisePropertyChanged("CurrentDocument"); //this fires
            }
        }

Using this approach, the binding statement in MainWindow.xaml errors out. Looking at Snoop binding error, it states that the CurrentDocument property is not found in MachineViewModel

System.Windows.Data Error: 40 : BindingExpression path error: 'CurrentDocument' property not found on 'object' ''MachineViewModel' (HashCode=27598891)'. BindingExpression:Path=CurrentDocument; DataItem='MachineViewModel' (HashCode=27598891); target element is 'MachineTreeView' (Name='MachineTreeView'); target property is 'MachineDocument' (type 'MachineDocument')

Why is it looking at the MachineViewModel when the binding is done in MainWindow?

Other binding properties in MainWindow do work as expected, this is the only UserControl binding I have though.

  • 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-13T09:09:50+00:00Added an answer on June 13, 2026 at 9:09 am

    Either it is a simple mistake

    • you’re setting MainMenuViewModel instead of MainWindowViewModel as MainWindow.DataContext

    or maybe

    • you set the DataContext for the UserControl in the wrong manner. Take a look at this Simple Pattern for Creating Re-useable UserControls to do it the right way.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This a data binding question in C#. I have a simple Person class: public
I am learning WPF and have this simple question. How do I set fill
Probably a simple question but one that eludes me nonetheless. I have a class:
A. Simple question. I have 3 instances of Repository that depends on the Configuration.
I have a simple Question.. Is it possible to use binding like this: <my:{Binding
I have hopefully a simple question. I have a ASPxGridView that I need to
in my application I made a very simple binding. I have a NSMutableArray bound
I have a simple datagrid to which I am binding a collection using ItemsSource.
I have a simple button: <Button Content=Login Command={Binding StartAction} IsEnabled={Binding Path=Loading, Converter={StaticResource InverseBooleanConverter}}/> As
I have simple php validation form that is halfway working. If you leave 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.