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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:24:52+00:00 2026-05-15T15:24:52+00:00

Working with the MVVM pattern, I have a pair of view model classes that

  • 0

Working with the MVVM pattern, I have a pair of view model classes that represent a two-tier data hierarchy, each with a corresponding UserControl that represents its view. Both view model classes implement INotifyPropertyChanged and the root level view model exposes a property that is relevant to both its own view and the child view.

The root level view acquires the root level view model as its data context and explicitly assigns a data context to its contained view. However, it also needs to bind one of the properties of the child view to the above-mentioned shared property. Here is how I have attempted to achieve this, but it’s not working:

<UserControl x:Name="rootView">
    <StackPanel>

        <!-- other controls here -->

        <my:ChildView
            DataContext="{Binding Path=SelectedChild}"
            EditingMode="{Binding ElementName=rootView, Path=DataContext.EditingMode />
    </StackPanel>
</UserControl>

Although there are no runtime binding errors and the child view correctly binds to the appropriate child view model instance, its EditingMode property is never set. I have run tests to verify that the corresponding view model property is being modified and that it is notifying this change via INotifyPropertyChanged, but the binding fails to detect it.

Is there a better way to declare this binding or have I made a more basic architectural error?

Many thanks for your advice,

Tim

Update: As requested, I am posting some code to show a very simplified version of my views and view models, together with the results of an experiment that I have conducted that may provide some additional clues.

// The relevant parts of the ParentViewModel class
public class ParentViewModel : INotifyPropertyChanged
{
    // Although not shown, the following properties
    // correctly participate in INotifyPropertyChanged

    public ChildViewModel SelectedChild { get; private set; }

    public ContentEditingMode EditingMode { get; private set; }
}

// The relevant parts of the ChildViewModel class
public class ChildViewModel : INotifyPropertyChanged
{
    // No properties of ChildViewModel affect this issue.
}

// The relevant parts of the ParentView class
public partial class ParentView : UserControl
{
    // No properties of ParentView affect this issue.
}

// The relevant members of the ChildView class
public partial class ChildView : UserControl
{
    public static readonly DependencyProperty EditingModeProperty =
        DependencyProperty.Register(
            "EditingMode",
            typeof(ContentEditingMode),
            typeof(PostView)
        );

    public ContentEditingMode EditingMode
    {
        get { return (ContentEditingMode)GetValue(EditingModeProperty); }
        set { SetValue(EditingModeProperty, value); }
    }
}

// The enumeration used for the EditingMode property
public enum ContentEditingMode
{
    Html,
    WYSYWIG
}

My intention is that the DataContext of the parent view instance will be assigned an instance of ParentViewModel and it will, in turn, assign the value of its SelectedChild property to the DataContext of the nested ChildView. All of this seems to work correctly, but the problem arises because the binding between ParentViewModel.EditingMode and ChildView.EditingMode does not work.

In an attempt to test whether there is a problem with my binding expression, I introduced a TextBlock adjacent to the ChildView and bound it similarly to the ParentViewModel.EditingMode property:

<UserControl x:Name="rootView">
    <StackPanel>

        <!-- other controls here -->

        <TextBlock Text="{Binding ElementName=rootView, Path=DataContext.EditingMode}" />

        <my:ChildView
            DataContext="{Binding Path=SelectedChild}"
            EditingMode="{Binding ElementName=rootView, Path=DataContext.EditingMode />
    </StackPanel>
</UserControl>

In this test, the TextBlock is correctly updated every time the source property changes. However, if I set a breakpoint on the setter of ChildView.EditingMode, it never gets hit.

I’m baffled !

  • 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-15T15:24:52+00:00Added an answer on May 15, 2026 at 3:24 pm

    The simplest way to fix this is in your view model. Implement an EditingMode property in the child view model and bind to it. That way, you don’t have to make any kind of guesses about what the right way to establish the binding might be; also, it’s something that you can test outside of the UI.

    Edit

    Actually the right solution is not quite as simple, but it’s worth knowing how to do.

    What you want is for EditingMode in the child control to efficiently inherit its value from the parent control. Does that sound like something that anything else in WPF does? Like just about every framework element that implements dependency properties?

    Implement EditingMode as a dependency property in both the parent and child UserControls and use property value inheritance, as described here. That takes the inheritance behavior out of the view model entirely and puts it where it belongs.

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

Sidebar

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.