more reactive UI work
This commit is contained in:
		@@ -27,6 +27,7 @@
 | 
			
		||||
    <PackageReference Include="Avalonia.Fonts.Inter" Version="11.0.10" />
 | 
			
		||||
    <!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
 | 
			
		||||
    <PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.3" />
 | 
			
		||||
    <PackageReference Include="ReactiveUI.SourceGenerators" Version="1.0.3" />
 | 
			
		||||
    <PackageReference Include="Splat" Version="15.1.1" />
 | 
			
		||||
    <PackageReference Include="System.Reactive" Version="6.0.1" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,8 @@
 | 
			
		||||
using System.Collections.ObjectModel;
 | 
			
		||||
using System.Reactive.Disposables;
 | 
			
		||||
using System.Reactive.Linq;
 | 
			
		||||
using ReactiveUI;
 | 
			
		||||
using ReactiveUI.SourceGenerators;
 | 
			
		||||
 | 
			
		||||
namespace StarsAssistant.ViewModels;
 | 
			
		||||
 | 
			
		||||
@@ -7,6 +10,24 @@ public partial class MainWindowViewModel : ViewModelBase, IActivatableViewModel
 | 
			
		||||
{
 | 
			
		||||
    public ViewModelActivator Activator { get; } = new ViewModelActivator();
 | 
			
		||||
 | 
			
		||||
    [ObservableAsProperty]
 | 
			
		||||
    private string _welcomeMessage;
 | 
			
		||||
 | 
			
		||||
    public MainWindowViewModel()
 | 
			
		||||
    {
 | 
			
		||||
        _welcomeMessage = "Lorem Ipsum";
 | 
			
		||||
        _welcomeMessageHelper = Observable.Return("Dolor sit amet")
 | 
			
		||||
            .ToProperty(this, x => x.WelcomeMessage);
 | 
			
		||||
 | 
			
		||||
        this.WhenActivated((CompositeDisposable disposables) => 
 | 
			
		||||
        {
 | 
			
		||||
            // /* handle activation */
 | 
			
		||||
            // Disposable
 | 
			
		||||
            //     .Create(() => { /* handle deactivation */ })
 | 
			
		||||
            //     .DisposeWith(disposables);
 | 
			
		||||
        });
 | 
			
		||||
    }        
 | 
			
		||||
 | 
			
		||||
    public ObservableCollection<PlanetViewModel> Planets { get; } = PlanetViewModel.LoadAll();
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -19,10 +19,10 @@
 | 
			
		||||
 | 
			
		||||
    <TabControl>
 | 
			
		||||
        <TabItem Header="Home">
 | 
			
		||||
            Welcome to Stars Assistant!
 | 
			
		||||
            <TextBlock x:Name="WelcomeText">Hi</TextBlock>
 | 
			
		||||
        </TabItem>
 | 
			
		||||
        <TabItem Header="DataGrid">
 | 
			
		||||
            <DataGrid ItemsSource="{Binding Planets}"   
 | 
			
		||||
            <DataGrid x:Name="PlanetsGrid"
 | 
			
		||||
                AutoGenerateColumns="True" IsReadOnly="True" 
 | 
			
		||||
                GridLinesVisibility="All"
 | 
			
		||||
                FrozenColumnCount="1"
 | 
			
		||||
 
 | 
			
		||||
@@ -4,6 +4,8 @@ using System.Diagnostics;
 | 
			
		||||
using System;
 | 
			
		||||
using StarsAssistant.ViewModels;
 | 
			
		||||
using Avalonia.Markup.Xaml;
 | 
			
		||||
using ReactiveUI;
 | 
			
		||||
using System.Reactive.Disposables;
 | 
			
		||||
 | 
			
		||||
namespace StarsAssistant.Views;
 | 
			
		||||
 | 
			
		||||
@@ -11,6 +13,21 @@ public partial class MainWindow : ReactiveWindow<MainWindowViewModel>
 | 
			
		||||
{
 | 
			
		||||
    public MainWindow()
 | 
			
		||||
    {
 | 
			
		||||
        AvaloniaXamlLoader.Load(this);
 | 
			
		||||
        this.WhenActivated(
 | 
			
		||||
 | 
			
		||||
            disposables => {
 | 
			
		||||
                this.OneWayBind(ViewModel,
 | 
			
		||||
                        viewModel => viewModel.Planets,
 | 
			
		||||
                        view => view.PlanetsGrid.ItemsSource)
 | 
			
		||||
                    .DisposeWith(disposables);
 | 
			
		||||
                this.OneWayBind(ViewModel, 
 | 
			
		||||
                        vm => vm.WelcomeMessage, 
 | 
			
		||||
                        v => v.WelcomeText.Text)
 | 
			
		||||
                    .DisposeWith(disposables);
 | 
			
		||||
            }
 | 
			
		||||
        );
 | 
			
		||||
        
 | 
			
		||||
        InitializeComponent();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user