在用WPF时使用轻量级MVVM框架:
1.实现完全的界面逻辑分离
2.可以省去很多繁琐且重复的代码量(清爽)
所以View层和ViewModel层直接是分开的,用Stylet关联,Model层通过orm框架的sqlsugar与数据库连接,并对应数据库的Model。
数据库使用的是sqlite.第三方图形化管理工具是dbeaver
具体该如何实现
1.创建一个ShellViewModel来管理应用程序的主窗口和视图之间的切换
以下是一个简单的示例,演示如何创建一个ShellViewModel来管理应用程序的主窗口和视图之间的切换。在这个示例中,我们使用了Stylet框架。创建ShellViewModel:
using Stylet;
public class ShellViewModel : Conductor<IScreen>.Collection.OneActive
{
public void ShowView1()
{
ActivateItem(new View1ViewModel());
}
public void ShowView2()
{
ActivateItem(new View2ViewModel());
}
}
在这个示例中,ShellViewModel继承自Conductor<IScreen>.Collection.OneActive,这是Stylet提供的用于管理多个视图的ViewModel基类。创建View1ViewModel和View2ViewModel:
using Stylet;
public class View1ViewModel : Screen
{
// View1的逻辑和数据
}
public class View2ViewModel : Screen
{
// View2的逻辑和数据
}
View1ViewModel和View2ViewModel分别表示两个不同的视图。
创建MainView:
<Window x:Class="YourNamespace.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Your Application" Height="400" Width="600">
<Grid>
<StackPanel Orientation="Horizontal">
<Button Content="Show View 1" />
<Button Content="Show View 2" />
</StackPanel>
<ContentControl x:Name="ActiveItem" />
</Grid>
</Window>
转载:
DBeaver连接SQLite数据库
没写完,有时间继续写。