create viewmodels for RepositoryWindow that can be swapped when locking/unlocking

This commit is contained in:
2025-12-05 01:14:00 +03:00
parent ad57307263
commit 9e5faa2ad4
6 changed files with 74 additions and 44 deletions

View File

@@ -1,49 +1,60 @@
<Window xmlns="https://github.com/avaloniaui" <Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:KeyKeeper.ViewModels"
x:Class="KeyKeeper.RepositoryWindow" x:Class="KeyKeeper.RepositoryWindow"
Title="KeyKeeper - Хранилище паролей" Title="KeyKeeper - Хранилище паролей"
Width="800" Width="800"
Height="600" Height="600"
Background="White"> Background="White"
x:DataType="vm:RepositoryWindowViewModel">
<Grid> <Window.DataTemplates>
<!-- Синий левый край --> <DataTemplate DataType="{x:Type vm:UnlockedRepositoryViewModel}">
<Border Width="200" <Grid>
Background="Blue" <!-- Синий левый край -->
HorizontalAlignment="Left" <Border Width="200"
VerticalAlignment="Stretch"/> Background="Blue"
<StackPanel Margin="20" HorizontalAlignment="Left"> HorizontalAlignment="Left"
<!-- Надпись KeyKeeper --> VerticalAlignment="Stretch"/>
<TextBlock Text="KeyKeeper" <StackPanel Margin="20" HorizontalAlignment="Left">
FontSize="32" <!-- Надпись KeyKeeper -->
FontWeight="Bold" <TextBlock Text="KeyKeeper"
HorizontalAlignment="Left" FontSize="32"
Margin="0,0,0,20"/> FontWeight="Bold"
HorizontalAlignment="Left"
<!-- Рамочка --> Margin="0,0,0,20"/>
<Border BorderBrush="Gray"
BorderThickness="1" <!-- Рамочка -->
CornerRadius="5" <Border BorderBrush="Gray"
Padding="20" BorderThickness="1"
Background="#F5F5F5" CornerRadius="5"
HorizontalAlignment="Left"> Padding="20"
Background="#F5F5F5"
<StackPanel HorizontalAlignment="Left"> HorizontalAlignment="Left">
<Button Content="All Passwords"
Width="120" <StackPanel HorizontalAlignment="Left">
Height="30" <Button Content="All Passwords"
Foreground="Black" Width="120"
HorizontalAlignment="Left"/> Height="30"
</StackPanel> Foreground="Black"
HorizontalAlignment="Left"/>
</Border> </StackPanel>
<!-- Save Passwords -->
<Button Content="Save Passwords" </Border>
Width="120" <!-- Save Passwords -->
Height="30" <Button Content="Save Passwords"
Foreground="White" Width="120"
HorizontalAlignment="Left" Height="30"
Margin="0,20,0,0"/> Foreground="White"
</StackPanel> HorizontalAlignment="Left"
</Grid> Margin="0,20,0,0"/>
</StackPanel>
</Grid>
</DataTemplate>
<DataTemplate DataType="{x:Type vm:LockedRepositoryViewModel}">
</DataTemplate>
</Window.DataTemplates>
<ContentControl Content="{Binding CurrentPage}"/>
</Window> </Window>

View File

@@ -1,7 +1,5 @@
using System; using System;
using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using KeyKeeper.PasswordStore; using KeyKeeper.PasswordStore;
using KeyKeeper.PasswordStore.Crypto; using KeyKeeper.PasswordStore.Crypto;

View File

@@ -0,0 +1,5 @@
namespace KeyKeeper.ViewModels;
public class LockedRepositoryViewModel : ViewModelBase
{
}

View File

@@ -0,0 +1,11 @@
namespace KeyKeeper.ViewModels;
public class RepositoryWindowViewModel : ViewModelBase
{
private object currentPage = new LockedRepositoryViewModel();
public object CurrentPage
{
get => currentPage;
set { currentPage = value; OnPropertyChanged(nameof(CurrentPage)); }
}
}

View File

@@ -0,0 +1,5 @@
namespace KeyKeeper.ViewModels;
public class UnlockedRepositoryViewModel : ViewModelBase
{
}

View File

@@ -84,7 +84,7 @@ namespace KeyKeeper.Views
{ {
var repositoryWindow = new RepositoryWindow() var repositoryWindow = new RepositoryWindow()
{ {
DataContext = this.DataContext, DataContext = new RepositoryWindowViewModel(),
PassStore = store, PassStore = store,
WindowStartupLocation = WindowStartupLocation.CenterScreen WindowStartupLocation = WindowStartupLocation.CenterScreen
}; };