Navigating between Views

BigH61 581 Reputation points
2022-09-01T19:06:01.29+00:00

I have created a very simple project to demonstrate a problem I have been grappling with for a few days. The full code is available to download at s!AuEmZJuOJ6_bgP9Jspx53kOML0Xang

Apologies for not posting the code but for what ever reason it site kept refusing to display large sections of the code.

Within a MainWindow I have 4 Buttons, 2 Buttons change the MainWindow view between OneView or TwoView. The reaming 2 buttons are meant to change the View within the view selected by the previous two buttons i.e. within OneView or TwoView. I say meant to because I cannot get this to work.
If I place two buttons within say OneView and bind them as I have buttons 3 and 4 then I can change the views within this view.
So I believe there is something about the Ancestry I am missing?

I would very much appreciate any assistance in resolving this issue.

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,670 questions
{count} votes

Accepted answer
  1. Jiale Xue - MSFT 31,516 Reputation points Microsoft Vendor
    2022-09-07T03:08:35.473+00:00

    Hi,@BigH61 :

    Please change the sentence to this <ContentControl Grid.Column="1" Content="{Binding DataContext.SelectedColorViewModel,RelativeSource={RelativeSource AncestorType=Window}}}"/> on OneView.

    Best Regards,
    Jiale


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful