Started UI separation

This commit is contained in:
Torben Nehmer 2024-09-22 22:12:46 +02:00
parent 269846f457
commit c2b265afd1
5 changed files with 82 additions and 16 deletions

View File

@ -0,0 +1,27 @@
using System.Collections.ObjectModel;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using ReactiveUI;
using ReactiveUI.SourceGenerators;
using Splat;
namespace StarsAssistant.ViewModels;
public partial class BuColViewModel : ViewModelBase, IActivatableViewModel
{
public ViewModelActivator Activator { get; } = new ViewModelActivator();
public BuColViewModel()
{
this.WhenActivated((CompositeDisposable disposables) =>
{
// /* handle activation */
// Disposable
// .Create(() => { /* handle deactivation */ })
// .DisposeWith(disposables);
});
}
public ObservableCollection<PlanetViewModel> Planets { get; } = PlanetViewModel.LoadAll();
}

View File

@ -1,4 +1,4 @@
using System.Collections.ObjectModel;

using System.Reactive.Disposables;
using System.Reactive.Linq;
using ReactiveUI;
@ -30,6 +30,6 @@ public partial class MainWindowViewModel : ViewModelBase, IActivatableViewModel
});
}
public ObservableCollection<PlanetViewModel> Planets { get; } = PlanetViewModel.LoadAll();
}

View File

@ -0,0 +1,23 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:StarsAssistant.ViewModels"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="StarsAssistant.Views.BuColView"
x:DataType="vm:BuColViewModel">
<DataGrid x:Name="PlanetsGrid"
ItemsSource="{Binding Planets}"
IsReadOnly="True"
GridLinesVisibility="All"
FrozenColumnCount="1"
BorderThickness="1" BorderBrush="Gray">
<DataGrid.Columns>
<DataGridTextColumn Header="Planet" Binding="{Binding Name}" />
<DataGridTextColumn Header="Value" Binding="{Binding Value}" />
</DataGrid.Columns>
</DataGrid>
</UserControl>

View File

@ -0,0 +1,25 @@
using System.Reactive.Disposables;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.ReactiveUI;
using ReactiveUI;
using StarsAssistant.ViewModels;
namespace StarsAssistant.Views;
public partial class BuColView : ReactiveUserControl<BuColViewModel>
{
public BuColView()
{
/*
this.WhenActivated(disposables =>
{
});
*/
this.ViewModel = new BuColViewModel();
InitializeComponent();
}
}

View File

@ -1,8 +1,9 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:StarsAssistant.ViewModels"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:StarsAssistant.ViewModels"
xmlns:views="clr-namespace:StarsAssistant.Views"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="StarsAssistant.Views.MainWindow"
x:DataType="vm:MainWindowViewModel"
@ -24,18 +25,8 @@
<TextBlock x:Name="DbPath" Grid.Row="0" Grid.Column="1" Margin="0 5" Padding="3"/>
</Grid>
</TabItem>
<TabItem Header="DataGrid">
<DataGrid x:Name="PlanetsGrid"
ItemsSource="{Binding Planets}"
IsReadOnly="True"
GridLinesVisibility="All"
FrozenColumnCount="1"
BorderThickness="1" BorderBrush="Gray">
<DataGrid.Columns>
<DataGridTextColumn Header="Planet" Binding="{Binding Name}" />
<DataGridTextColumn Header="Value" Binding="{Binding Value}" />
</DataGrid.Columns>
</DataGrid>
<TabItem Header="BuCol">
<views:BuColView />
</TabItem>
</TabControl>
</Window>