4

I have created a project using Avalonia UI MVVM C# project. and I am very new to this. I am using the Community Toolkit MVVM package, not the Reactive UI package. There are two pages, "MainWindow" and "SettingWindow". There is a button on the "MainWindow" page. Once the user clicks that button, user should be navigated to the "Settings" page. How can I accomplish this using the Community Toolkit MVVM package in Avalonia UI?

MainWindow codebehind

public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            DataContext= new MainWindowViewModel();
        }
    }

MainWindow viewModel Code

[INotifyPropertyChanged]
    public partial class MainWindowViewModel
    {
        [ObservableProperty]
        public string greeting = "Welcome to Avalonia!";

        [RelayCommand]
        public void GotoSettings()
        {
          //navigate to setting window
        }
    }

SettingWindow codebehind

 public partial class SettingWindow : Window
        {
            public SettingWindow()
            {
                InitializeComponent();
                DataContext = new SettingWindowViewModel();
            }
        }

SettingWindow ViewModel code

[INotifyPropertyChanged]
public partial class SettingWindowViewModel
{
    public string greeting => "setting page";
}
yasith rangana
  • 196
  • 2
  • 12

0 Answers0