Как сохранить состояние(значение) в свойстве класса mvvm

Я использую UserControlы, при каждом выборе другого UserContolа, у меня пустое значение.

Мое основное окно, где выборка идет между UserContolами

В INPC находится OnPropertyChanged();

class ChelVM : INPC
    {
        public ChelVM()
        {
            ScheduleVM = new ScheduleVM();
            NotificationVM = new NotificationVM();
        }

        public ICommand ScheduleCommand => new DefaultCommand(obj =>
        {
            CurrentView = ScheduleVM;
        });

        public ScheduleVM _scheduleVM;
        public ScheduleVM ScheduleVM 
        { get => _scheduleVM;
          set { _scheduleVM = value; OnPropertyChanged(); }
        }

        public ICommand NotificationCommand => new DefaultCommand(obj =>
        {
            CurrentView = NotificationVM;
        });

        public NotificationVM NotificationVM { get; set; }

        private object _currentView;

        public object CurrentView 
        {
            get => _currentView;
            set
            {
                _currentView = value;
                OnPropertyChanged();
            } 
        }
    }

UserControls

class NotificationVM : INPC
    {
        private string _text;
        public string Text
        {
            get => _text;
            set
            {
                _text = _text + value;
                OnPropertyChanged();
            }
        }
    }

<UserControl x:Class="ScheduleBookRKSI.ViewModels.UserControls.NotificationDV"
             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" 
             xmlns:local="clr-namespace:ScheduleBookRKSI.ViewModels.UserControls"
             xmlns:mvvm="clr-namespace:ScheduleBookRKSI.ViewModels.ChelWindowVM"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">

    <UserControl.DataContext>
        <mvvm:NotificationVM/>
    </UserControl.DataContext>

        <Grid Background="#272537">
        <RichTextBox Background="#272537" Foreground="White"
                     HorizontalAlignment="Center" VerticalAlignment="Center"
                     Height="430" Width="800"
                     Margin="0,5,0,5" SelectionBrush="Black" BorderBrush="#272537">
            <FlowDocument>
                <Paragraph TextAlignment="Center">
                    <Run Text="{Binding Text}"/>
                </Paragraph>
            </FlowDocument>
        </RichTextBox>
    </Grid>
</UserControl>

 class ScheduleVM : INPC
    {
        private string _text;
        public string Text
        {
            get => _text;
            set
            {
                _text = _text + value;
                OnPropertyChanged();
            }
        }
    }
<UserControl x:Class="ScheduleBookRKSI.ViewModels.UserControls.ScheduleDV"
             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" 
             xmlns:local="clr-namespace:ScheduleBookRKSI.ViewModels.UserControls"
             xmlns:mvvm="clr-namespace:ScheduleBookRKSI.ViewModels.ChelWindowVM"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">

    <UserControl.DataContext>
        <mvvm:ScheduleVM/>
    </UserControl.DataContext>

    <Grid Background="#272537">
        <TextBox Background="#272537" Foreground="White"
                     HorizontalAlignment="Center" VerticalAlignment="Center"
                     Height="220" Width="300"
                     Margin="0,5,0,5" Text="{Binding Text}"/>

    </Grid>
</UserControl>


Мне нужно сохранять значения textblock, которые находятся в UserContolах, пока открыто ChelVM(ChelView) Может при запаковке в object оно в стек уходит, поэтому и не сохраняется?


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