更改了菜单点击导航模式,新增了设备详情页
This commit is contained in:
@@ -54,6 +54,8 @@ public partial class App : Application
|
||||
container.AddSingleton<DataTransformViewModel>();
|
||||
container.AddSingleton<VariableTableViewModel>();
|
||||
container.AddSingleton<VariableTableView>();
|
||||
container.AddScoped<DeviceDetailViewModel>();
|
||||
container.AddScoped<DeviceDetailView>();
|
||||
Services = container.BuildServiceProvider();
|
||||
// 启动服务
|
||||
Services.GetRequiredService<GrowlNotificationService>();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using PMSWPF.Enums;
|
||||
using PMSWPF.ViewModels;
|
||||
|
||||
namespace PMSWPF.Models;
|
||||
|
||||
@@ -11,6 +12,8 @@ public class MenuBean
|
||||
public int ParentId { get; set; }
|
||||
public int DataId { get; set; }
|
||||
public MenuType Type { get; set; }
|
||||
|
||||
public ViewModelBase ViewModel { get; set; }
|
||||
public Object? Data { get; set; }
|
||||
public List<MenuBean> Items { get; set; }
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PMSWPF.Data.Repositories;
|
||||
using PMSWPF.Enums;
|
||||
@@ -7,6 +8,7 @@ using PMSWPF.Extensions;
|
||||
using PMSWPF.Helper;
|
||||
using PMSWPF.Message;
|
||||
using PMSWPF.Models;
|
||||
using PMSWPF.ViewModels;
|
||||
|
||||
namespace PMSWPF.Services;
|
||||
|
||||
@@ -61,13 +63,16 @@ public partial class DataServices : ObservableRecipient, IRecipient<LoadMessage>
|
||||
switch (menuBean.Type)
|
||||
{
|
||||
case MenuType.MainMenu:
|
||||
menuBean.ViewModel= GetMainViewModel(menuBean.Name);
|
||||
break;
|
||||
case MenuType.DeviceMenu:
|
||||
menuBean.ViewModel = App.Current.Services.GetRequiredService<DeviceDetailViewModel>();
|
||||
menuBean.Data= Devices.FirstOrDefault(d => d.Id == menuBean.DataId);
|
||||
break;
|
||||
case MenuType.VariableTableMenu:
|
||||
menuBean.Data= FindVarTableForDevice(menuBean.DataId);
|
||||
// menuBean.Data= Devices.FirstOrDefault(d => d.Id == menuBean.DataId);
|
||||
var varTableVM = App.Current.Services.GetRequiredService<VariableTableViewModel>();
|
||||
varTableVM.VariableTable = FindVarTableForDevice(menuBean.DataId);
|
||||
menuBean.ViewModel = varTableVM;
|
||||
break;
|
||||
case MenuType.AddVariableTableMenu:
|
||||
break;
|
||||
@@ -79,6 +84,28 @@ public partial class DataServices : ObservableRecipient, IRecipient<LoadMessage>
|
||||
}
|
||||
}
|
||||
|
||||
private ViewModelBase GetMainViewModel(string name)
|
||||
{
|
||||
ViewModelBase navgateVM = App.Current.Services.GetRequiredService<HomeViewModel>();
|
||||
switch (name)
|
||||
{
|
||||
case "主页":
|
||||
navgateVM = App.Current.Services.GetRequiredService<HomeViewModel>();
|
||||
break;
|
||||
case "设备":
|
||||
navgateVM = App.Current.Services.GetRequiredService<DevicesViewModel>();
|
||||
break;
|
||||
case "数据转换":
|
||||
navgateVM = App.Current.Services.GetRequiredService<DataTransformViewModel>();
|
||||
break;
|
||||
case "设置":
|
||||
navgateVM = App.Current.Services.GetRequiredService<SettingViewModel>();
|
||||
break;
|
||||
}
|
||||
return navgateVM;
|
||||
|
||||
}
|
||||
|
||||
private VariableTable FindVarTableForDevice(int vtableId)
|
||||
{
|
||||
VariableTable varTable = null;
|
||||
|
||||
9
ViewModels/DeviceDetailViewModel.cs
Normal file
9
ViewModels/DeviceDetailViewModel.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace PMSWPF.ViewModels;
|
||||
|
||||
public class DeviceDetailViewModel:ViewModelBase
|
||||
{
|
||||
public override void OnLoaded()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,12 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using PMSWPF.Models;
|
||||
|
||||
namespace PMSWPF.ViewModels;
|
||||
|
||||
public class VariableTableViewModel : ViewModelBase
|
||||
partial class VariableTableViewModel : ViewModelBase
|
||||
{
|
||||
[ObservableProperty]
|
||||
private VariableTable variableTable;
|
||||
public override void OnLoaded()
|
||||
{
|
||||
}
|
||||
|
||||
12
Views/DeviceDetailView.xaml
Normal file
12
Views/DeviceDetailView.xaml
Normal file
@@ -0,0 +1,12 @@
|
||||
<UserControl x:Class="PMSWPF.Views.DeviceDetailView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:PMSWPF.Views"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="300" d:DesignWidth="300">
|
||||
<Grid>
|
||||
<TextBlock Text="DeviceDetail" FontSize="40" HorizontalAlignment="Center" VerticalAlignment="Center" />
|
||||
</Grid>
|
||||
</UserControl>
|
||||
14
Views/DeviceDetailView.xaml.cs
Normal file
14
Views/DeviceDetailView.xaml.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.Windows.Controls;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using PMSWPF.ViewModels;
|
||||
|
||||
namespace PMSWPF.Views;
|
||||
|
||||
public partial class DeviceDetailView : UserControl
|
||||
{
|
||||
public DeviceDetailView()
|
||||
{
|
||||
InitializeComponent();
|
||||
DataContext = App.Current.Services.GetRequiredService<DeviceDetailViewModel>();
|
||||
}
|
||||
}
|
||||
@@ -76,7 +76,6 @@
|
||||
ItemsSource="{Binding Devices}"
|
||||
ItemTemplate="{StaticResource DeviceItemTemplate}"
|
||||
SelectionMode="Single" />
|
||||
|
||||
</StackPanel>
|
||||
|
||||
</UserControl>
|
||||
@@ -15,9 +15,4 @@ public partial class DevicesView : UserControl
|
||||
{
|
||||
}
|
||||
|
||||
private async void DevicesView_OnLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// var devicesViewModel = (DevicesViewModel)this.DataContext;
|
||||
// await devicesViewModel.OnLoadedAsync();
|
||||
}
|
||||
}
|
||||
@@ -40,45 +40,9 @@
|
||||
SelectionFollowsFocus="Disabled"
|
||||
MenuItemsSource="{Binding Menus}"
|
||||
MenuItemTemplate="{StaticResource NavigationViewMenuItem}"
|
||||
ItemInvoked="NavigationView_OnItemInvoked"
|
||||
SelectionChanged="NavigationView_OnSelectionChanged"
|
||||
SelectionChanged="NavigationView_SelectionChanged"
|
||||
>
|
||||
|
||||
<!-- <ui:NavigationView.MenuItems> -->
|
||||
<!-- <ui:NavigationViewItem -->
|
||||
<!-- Content="主页" -->
|
||||
<!-- Tag="Home"> -->
|
||||
<!-- <ui:NavigationViewItem.Icon> -->
|
||||
<!-- <ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Home}" /> -->
|
||||
<!-- </ui:NavigationViewItem.Icon> -->
|
||||
<!-- </ui:NavigationViewItem> -->
|
||||
<!-- <ui:NavigationViewItem -->
|
||||
<!-- Content="设备" -->
|
||||
<!-- Tag="Devices"> -->
|
||||
<!-- <ui:NavigationViewItem.Icon> -->
|
||||
<!-- <ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Devices2}" /> -->
|
||||
<!-- </ui:NavigationViewItem.Icon> -->
|
||||
<!-- </ui:NavigationViewItem> -->
|
||||
<!-- <ui:NavigationViewItem -->
|
||||
<!-- Content="数据转换" -->
|
||||
<!-- Tag="DataTransform"> -->
|
||||
<!-- <ui:NavigationViewItem.Icon> -->
|
||||
<!-- <ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Switch}" /> -->
|
||||
<!-- </ui:NavigationViewItem.Icon> -->
|
||||
<!-- </ui:NavigationViewItem> -->
|
||||
<!-- <ui:NavigationViewItem Tag="Setting" Content="设置"> -->
|
||||
<!-- <ui:NavigationViewItem.Icon> -->
|
||||
<!-- <ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Settings}" /> -->
|
||||
<!-- </ui:NavigationViewItem.Icon> -->
|
||||
<!-- </ui:NavigationViewItem> -->
|
||||
<!-- <ui:NavigationViewItem Content="关于"> -->
|
||||
<!-- <ui:NavigationViewItem.Icon> -->
|
||||
<!-- <ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Info}" /> -->
|
||||
<!-- </ui:NavigationViewItem.Icon> -->
|
||||
<!-- </ui:NavigationViewItem> -->
|
||||
<!-- -->
|
||||
<!-- </ui:NavigationView.MenuItems> -->
|
||||
|
||||
<ui:NavigationView.AutoSuggestBox>
|
||||
<ui:AutoSuggestBox AutomationProperties.Name="Search">
|
||||
<ui:AutoSuggestBox.QueryIcon>
|
||||
@@ -89,21 +53,33 @@
|
||||
|
||||
|
||||
<Grid>
|
||||
|
||||
<!-- 数据模版绑定不同的View显示 -->
|
||||
<ContentControl Content="{Binding CurrentViewModel}">
|
||||
<ContentControl.Resources>
|
||||
<!-- 主页 -->
|
||||
<DataTemplate DataType="{x:Type vm:HomeViewModel}">
|
||||
<local:HomeView />
|
||||
</DataTemplate>
|
||||
<!-- 设备列表页 -->
|
||||
<DataTemplate DataType="{x:Type vm:DevicesViewModel}">
|
||||
<local:DevicesView />
|
||||
</DataTemplate>
|
||||
<!-- 数据转换页 -->
|
||||
<DataTemplate DataType="{x:Type vm:DataTransformViewModel}">
|
||||
<local:DataTransformView />
|
||||
</DataTemplate>
|
||||
<!-- 设置页 -->
|
||||
<DataTemplate DataType="{x:Type vm:SettingViewModel}">
|
||||
<local:SettingView />
|
||||
</DataTemplate>
|
||||
<!-- 设备详情页 -->
|
||||
<DataTemplate DataType="{x:Type vm:DeviceDetailViewModel}">
|
||||
<local:DeviceDetailView />
|
||||
</DataTemplate>
|
||||
<!-- 设备变量页 -->
|
||||
<DataTemplate DataType="{x:Type vm:VariableTableViewModel}">
|
||||
<local:VariableTableView />
|
||||
</DataTemplate>
|
||||
</ContentControl.Resources>
|
||||
</ContentControl>
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ using CommunityToolkit.Mvvm.Messaging;
|
||||
using iNKORE.UI.WPF.Modern.Controls;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PMSWPF.Enums;
|
||||
using PMSWPF.Helper;
|
||||
using PMSWPF.Message;
|
||||
using PMSWPF.Models;
|
||||
@@ -18,6 +19,7 @@ public partial class MainView : Window
|
||||
{
|
||||
private readonly ILogger<MainView> _logger;
|
||||
private MainViewModel _viewModel;
|
||||
|
||||
public MainView(MainViewModel viewModel, ILogger<MainView> logger)
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -34,33 +36,31 @@ public partial class MainView : Window
|
||||
/// <param name="args"></param>
|
||||
private void NavigationView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
|
||||
{
|
||||
var item = args.SelectedItem as NavigationViewItem;
|
||||
ViewModelBase navgateVM = App.Current.Services.GetRequiredService<HomeViewModel>();
|
||||
switch (item.Tag)
|
||||
try
|
||||
{
|
||||
case "Home":
|
||||
// mainViewModel.NavgateTo<HomeViewModel>();
|
||||
navgateVM = App.Current.Services.GetRequiredService<HomeViewModel>();
|
||||
_logger.LogInformation("导航到到主页面");
|
||||
break;
|
||||
case "Devices":
|
||||
navgateVM = App.Current.Services.GetRequiredService<DevicesViewModel>();
|
||||
// mainViewModel.NavgateTo<DevicesViewModel>();
|
||||
_logger.LogInformation("导航到到设备页面");
|
||||
break;
|
||||
case "DataTransform":
|
||||
navgateVM = App.Current.Services.GetRequiredService<DataTransformViewModel>();
|
||||
// mainViewModel.NavgateTo<DataTransformViewModel>();
|
||||
_logger.LogInformation("导航到到数据转换页面");
|
||||
break;
|
||||
case "Setting":
|
||||
// mainViewModel.NavgateTo<SettingViewModel>();
|
||||
navgateVM = App.Current.Services.GetRequiredService<SettingViewModel>();
|
||||
_logger.LogInformation("导航到到设备页面");
|
||||
break;
|
||||
var menu = args.SelectedItem as MenuBean;
|
||||
if (menu == null)
|
||||
throw new ArgumentException("选择的菜单项为空!");
|
||||
|
||||
switch (menu.Type)
|
||||
{
|
||||
case MenuType.MainMenu:
|
||||
case MenuType.DeviceMenu:
|
||||
case MenuType.VariableTableMenu:
|
||||
if (menu.ViewModel == null)
|
||||
throw new ArgumentException($"菜单项:{menu.Name},没有绑定对象的ViewModel");
|
||||
MessageHelper.SendNavgatorMessage(menu.ViewModel);
|
||||
_logger.LogInformation($"导航到:{menu.Name}");
|
||||
break;
|
||||
case MenuType.AddVariableTableMenu:
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
NotificationHelper.ShowMessage(e.Message, NotificationType.Error);
|
||||
_logger.LogError(e.Message);
|
||||
}
|
||||
|
||||
MessageHelper.SendNavgatorMessage(navgateVM);
|
||||
}
|
||||
|
||||
private async void MainView_OnLoaded(object sender, RoutedEventArgs e)
|
||||
@@ -71,7 +71,7 @@ public partial class MainView : Window
|
||||
private void NavigationView_OnItemInvoked(NavigationView sender, NavigationViewItemInvokedEventArgs args)
|
||||
{
|
||||
ViewModelBase navgateVM = App.Current.Services.GetRequiredService<HomeViewModel>();
|
||||
Object parameter =null;
|
||||
|
||||
switch (args.InvokedItem)
|
||||
{
|
||||
case "主页":
|
||||
@@ -95,13 +95,7 @@ public partial class MainView : Window
|
||||
_logger.LogInformation("导航到到设备页面");
|
||||
break;
|
||||
}
|
||||
|
||||
MessageHelper.SendNavgatorMessage(navgateVM,parameter);
|
||||
}
|
||||
|
||||
private void NavigationView_OnSelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
|
||||
{
|
||||
var selectMenu= args.SelectedItem as MenuBean;
|
||||
|
||||
MessageHelper.SendNavgatorMessage(navgateVM);
|
||||
}
|
||||
}
|
||||
@@ -4,15 +4,17 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:ikw="http://schemas.inkore.net/lib/ui/wpf"
|
||||
xmlns:vm="clr-namespace:PMSWPF.ViewModels"
|
||||
mc:Ignorable="d"
|
||||
d:DataContext="{d:DesignInstance vm:VariableTableViewModel}"
|
||||
d:DesignHeight="300" d:DesignWidth="300">
|
||||
<ikw:SimpleStackPanel Spacing="5">
|
||||
|
||||
<ikw:SimpleStackPanel Orientation="Horizontal" Spacing="10">
|
||||
<TextBlock Text="变量表名称:" /> <TextBlock Text="默认变量表" />
|
||||
<TextBlock Text="变量表名称:" /> <TextBlock Text="{Binding VariableTable.Name}" />
|
||||
</ikw:SimpleStackPanel>
|
||||
<ikw:SimpleStackPanel Orientation="Horizontal" Spacing="10">
|
||||
<TextBlock Text="变量表描述:" /> <TextBlock Text="默认变量表" />
|
||||
<TextBlock Text="变量表描述:" /> <TextBlock Text="{Binding VariableTable.Description}" />
|
||||
</ikw:SimpleStackPanel>
|
||||
<ikw:SimpleStackPanel Orientation="Horizontal" Spacing="10">
|
||||
<TextBlock Text="所属设备:" /> <TextBlock Text="默认变量表" />
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
using System.Windows.Controls;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using PMSWPF.ViewModels;
|
||||
|
||||
namespace PMSWPF.Views;
|
||||
|
||||
public partial class VariableTableView : UserControl
|
||||
{
|
||||
public VariableTableView(VariableTableViewModel viewModel)
|
||||
public VariableTableView()
|
||||
{
|
||||
InitializeComponent();
|
||||
DataContext = viewModel;
|
||||
DataContext = App.Current.Services.GetRequiredService<VariableTableViewModel>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user