DataContext в C#

На главном окне есть DataContext со статичным ресурсом ViewModelLocator и фрейм с Binding

<Window DataContext="{Binding MainViewModel, Source={StaticResource ViewModelLocator}}" x:Class="SystemBackdropTypes.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:local="clr-namespace:SystemBackdropTypes"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:viewmodels="clr-namespace:SystemBackdropTypes.ViewModels"
        Background="Transparent"
        Title="DWM System Backdrop Type Sample" Height="450" Width="800" Loaded="Window_Loaded"
        mc:Ignorable="d">



    <Grid>
        <Frame x:Name="_this" Content="{Binding PageSource}" NavigationUIVisibility="Hidden" />

Как это всё написать на C#? Мне нужно получить PageSource из MainViewModel и загрузить в фрейм

MainViewModel:

using DevExpress.Mvvm;
using System.Windows.Controls;
using SystemBackdropTypes;
using SystemBackdropTypes.Pages;
using SystemBackdropTypes.Services;

namespace SystemBackdropTypes.ViewModels
{
    public class MainViewModel : BindableBase
    {
        private readonly PageService _pageService;

        public Page PageSource { get; set; }

        public MainViewModel(PageService pageService)
        {
            _pageService = pageService;


            _pageService.OnPageChanged += (page) => PageSource = page;
            _pageService.ChangePage(new LoginPage());
        }
    }
}

Я пытался сделать что-то типа:

_this.Content = DataContext.PageSource;

и

Binding binding = BindingOperations.GetBinding(_this, Frame.ContentProperty);
_this.Content = binding.Source;

Я новичок в WPF, так что строго не судите)


Ответы (0 шт):