实现了导航功能
This commit is contained in:
7
App.xaml
7
App.xaml
@@ -2,13 +2,14 @@
|
|||||||
x:Class="PMSWPF.App"
|
x:Class="PMSWPF.App"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
|
||||||
xmlns:local="clr-namespace:PMSWPF"
|
xmlns:local="clr-namespace:PMSWPF"
|
||||||
StartupUri="Views/PlcListView.xaml">
|
>
|
||||||
<Application.Resources>
|
<Application.Resources>
|
||||||
<ResourceDictionary>
|
<ResourceDictionary>
|
||||||
<ResourceDictionary.MergedDictionaries>
|
<ResourceDictionary.MergedDictionaries>
|
||||||
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/SkinDefault.xaml" />
|
<ui:ThemeResources/>
|
||||||
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Theme.xaml" />
|
<ui:XamlControlsResources/>
|
||||||
</ResourceDictionary.MergedDictionaries>
|
</ResourceDictionary.MergedDictionaries>
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
</Application.Resources>
|
</Application.Resources>
|
||||||
|
|||||||
62
App.xaml.cs
62
App.xaml.cs
@@ -14,29 +14,55 @@ namespace PMSWPF
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class App : Application
|
public partial class App : Application
|
||||||
{
|
{
|
||||||
[STAThread]
|
public new static App Current => (App)Application.Current;
|
||||||
static void Main(string[] args)
|
public IServiceProvider Services { get; }
|
||||||
|
|
||||||
|
public App()
|
||||||
{
|
{
|
||||||
using IHost host = CreateHostBuilder(args).Build();
|
var container = new ServiceCollection();
|
||||||
host.Start();
|
container.AddSingleton<NavgatorServices>();
|
||||||
App app = new App();
|
container.AddSingleton<MainViewModel>();
|
||||||
app.InitializeComponent();
|
container.AddSingleton<HomeViewModel>();
|
||||||
app.MainWindow = host.Services.GetRequiredService<MainView>();
|
container.AddSingleton<DevicesViewModel>();
|
||||||
app.MainWindow.Visibility = Visibility.Visible;
|
container.AddSingleton<DataTransformViewModel>();
|
||||||
app.Run();
|
container.AddSingleton<MainView>(dp => new MainView()
|
||||||
|
{ DataContext = dp.GetRequiredService<MainViewModel>() });
|
||||||
|
container.AddSingleton<HomeView>();
|
||||||
|
container.AddSingleton<DevicesView>();
|
||||||
|
container.AddSingleton<DataTransformViewModel>();
|
||||||
|
|
||||||
|
Services = container.BuildServiceProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IHostBuilder CreateHostBuilder(string[] args)
|
protected override void OnStartup(StartupEventArgs e)
|
||||||
{
|
{
|
||||||
return Host.CreateDefaultBuilder(args).ConfigureServices(services =>
|
base.OnStartup(e);
|
||||||
{
|
MainWindow = Services.GetRequiredService<MainView>();
|
||||||
|
MainWindow.Show();
|
||||||
services.AddHostedService<DemoBackgroundService>();
|
|
||||||
services.AddSingleton<MainView>();
|
|
||||||
services.AddSingleton<MainViewModel>();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// [STAThread]
|
||||||
|
// static void Main(string[] args)
|
||||||
|
// {
|
||||||
|
// using IHost host = CreateHostBuilder(args).Build();
|
||||||
|
// host.Start();
|
||||||
|
// App app = new App();
|
||||||
|
// app.InitializeComponent();
|
||||||
|
// app.MainWindow = host.Services.GetRequiredService<MainView>();
|
||||||
|
// app.MainWindow.Visibility = Visibility.Visible;
|
||||||
|
// app.Run();
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// private static IHostBuilder CreateHostBuilder(string[] args)
|
||||||
|
// {
|
||||||
|
// return Host.CreateDefaultBuilder(args).ConfigureServices(services =>
|
||||||
|
// {
|
||||||
|
//
|
||||||
|
// services.AddHostedService<DemoBackgroundService>();
|
||||||
|
// services.AddSingleton<MainView>();
|
||||||
|
// services.AddSingleton<MainViewModel>();
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -7,14 +7,10 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<UseWPF>true</UseWPF>
|
<UseWPF>true</UseWPF>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ApplicationDefinition Remove="App.xaml" />
|
|
||||||
<Page Include="App.xaml" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
|
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
|
||||||
<PackageReference Include="HandyControl" Version="3.5.1" />
|
<PackageReference Include="HandyControl" Version="3.5.1" />
|
||||||
|
<PackageReference Include="iNKORE.UI.WPF.Modern" Version="0.10.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.5" />
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.5" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.5" />
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.5" />
|
||||||
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.135" />
|
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.135" />
|
||||||
|
|||||||
29
Services/NavgatorServices.cs
Normal file
29
Services/NavgatorServices.cs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
using System.Windows;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using PMSWPF.ViewModels;
|
||||||
|
|
||||||
|
namespace PMSWPF.Services;
|
||||||
|
|
||||||
|
public class NavgatorServices
|
||||||
|
{
|
||||||
|
private ViewModelBase currentViewModel;
|
||||||
|
|
||||||
|
public ViewModelBase CurrentViewModel
|
||||||
|
{
|
||||||
|
get { return currentViewModel; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
currentViewModel = value;
|
||||||
|
OnViewModelChanged?.Invoke();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public event Action OnViewModelChanged ;
|
||||||
|
|
||||||
|
public void NavigateTo<T>() where T : ViewModelBase
|
||||||
|
{
|
||||||
|
// Application.Current
|
||||||
|
CurrentViewModel = App.Current.Services.GetService<T>();
|
||||||
|
}
|
||||||
|
}
|
||||||
6
ViewModels/DataTransformViewModel.cs
Normal file
6
ViewModels/DataTransformViewModel.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace PMSWPF.ViewModels;
|
||||||
|
|
||||||
|
public class DataTransformViewModel:ViewModelBase
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
6
ViewModels/DevicesViewModel.cs
Normal file
6
ViewModels/DevicesViewModel.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace PMSWPF.ViewModels;
|
||||||
|
|
||||||
|
public class DevicesViewModel:ViewModelBase
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
6
ViewModels/HomeViewModel.cs
Normal file
6
ViewModels/HomeViewModel.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace PMSWPF.ViewModels;
|
||||||
|
|
||||||
|
public class HomeViewModel:ViewModelBase
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3,15 +3,30 @@ using CommunityToolkit.Mvvm.Messaging;
|
|||||||
using PMSWPF.Data.Entities;
|
using PMSWPF.Data.Entities;
|
||||||
using PMSWPF.Message;
|
using PMSWPF.Message;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using PMSWPF.Services;
|
||||||
|
|
||||||
namespace PMSWPF.ViewModels
|
namespace PMSWPF.ViewModels
|
||||||
{
|
{
|
||||||
partial class MainViewModel : ObservableRecipient, IRecipient<MyMessage>
|
partial class MainViewModel : ObservableRecipient, IRecipient<MyMessage>
|
||||||
{
|
{
|
||||||
|
private readonly NavgatorServices _navgatorServices;
|
||||||
|
|
||||||
public MainViewModel()
|
[ObservableProperty]
|
||||||
|
private ViewModelBase currentViewModel;
|
||||||
|
public MainViewModel(NavgatorServices navgatorServices)
|
||||||
{
|
{
|
||||||
|
_navgatorServices = navgatorServices;
|
||||||
|
_navgatorServices.OnViewModelChanged += () =>
|
||||||
|
{
|
||||||
|
CurrentViewModel = _navgatorServices.CurrentViewModel;
|
||||||
|
};
|
||||||
IsActive = true;
|
IsActive = true;
|
||||||
|
CurrentViewModel = new HomeViewModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void NavgateTo<T>() where T : ViewModelBase
|
||||||
|
{
|
||||||
|
_navgatorServices.NavigateTo<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
string text = "Hello Count:";
|
string text = "Hello Count:";
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
|
||||||
using PMSWPF.Data.Entities;
|
|
||||||
using System.Collections.ObjectModel;
|
|
||||||
|
|
||||||
namespace PMSWPF.ViewModels
|
|
||||||
{
|
|
||||||
public partial class PlcListViewModel : ObservableRecipient
|
|
||||||
{
|
|
||||||
[ObservableProperty]
|
|
||||||
private ObservableCollection<PLC> plcList;
|
|
||||||
public PlcListViewModel()
|
|
||||||
{
|
|
||||||
plcList = new ObservableCollection<PLC>();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
6
ViewModels/ViewModelBase.cs
Normal file
6
ViewModels/ViewModelBase.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace PMSWPF.ViewModels;
|
||||||
|
|
||||||
|
public class ViewModelBase
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
12
Views/DataTransformView.xaml
Normal file
12
Views/DataTransformView.xaml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<UserControl x:Class="PMSWPF.Views.DataTransformView"
|
||||||
|
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="DataTransformView" FontSize="40" HorizontalAlignment="Center" VerticalAlignment="Center"></TextBlock>
|
||||||
|
</Grid>
|
||||||
|
</UserControl>
|
||||||
11
Views/DataTransformView.xaml.cs
Normal file
11
Views/DataTransformView.xaml.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
using System.Windows.Controls;
|
||||||
|
|
||||||
|
namespace PMSWPF.Views;
|
||||||
|
|
||||||
|
public partial class DataTransformView : UserControl
|
||||||
|
{
|
||||||
|
public DataTransformView()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
12
Views/DevicesView.xaml
Normal file
12
Views/DevicesView.xaml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<UserControl x:Class="PMSWPF.Views.DevicesView"
|
||||||
|
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="DevicesView" FontSize="40" HorizontalAlignment="Center" VerticalAlignment="Center"></TextBlock>
|
||||||
|
</Grid>
|
||||||
|
</UserControl>
|
||||||
11
Views/DevicesView.xaml.cs
Normal file
11
Views/DevicesView.xaml.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
using System.Windows.Controls;
|
||||||
|
|
||||||
|
namespace PMSWPF.Views;
|
||||||
|
|
||||||
|
public partial class DevicesView : UserControl
|
||||||
|
{
|
||||||
|
public DevicesView()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
12
Views/HomeView.xaml
Normal file
12
Views/HomeView.xaml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<UserControl x:Class="PMSWPF.Views.HomeView"
|
||||||
|
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="HomeView" FontSize="40" HorizontalAlignment="Center" VerticalAlignment="Center"></TextBlock>
|
||||||
|
</Grid>
|
||||||
|
</UserControl>
|
||||||
11
Views/HomeView.xaml.cs
Normal file
11
Views/HomeView.xaml.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
using System.Windows.Controls;
|
||||||
|
|
||||||
|
namespace PMSWPF.Views;
|
||||||
|
|
||||||
|
public partial class HomeView : UserControl
|
||||||
|
{
|
||||||
|
public HomeView()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,29 +3,123 @@
|
|||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:hc="https://handyorg.github.io/handycontrol"
|
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
|
||||||
|
xmlns:ikw="http://schemas.inkore.net/lib/ui/wpf"
|
||||||
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
|
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
|
||||||
xmlns:local="clr-namespace:PMSWPF.Views"
|
xmlns:local="clr-namespace:PMSWPF.Views"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:vm="clr-namespace:PMSWPF.ViewModels"
|
xmlns:vm="clr-namespace:PMSWPF.ViewModels"
|
||||||
Title="MainView"
|
Title="MainView"
|
||||||
Width="800"
|
Width="800"
|
||||||
Height="450"
|
Height="600"
|
||||||
|
ui:WindowHelper.UseModernWindowStyle="True"
|
||||||
|
ui:WindowHelper.SystemBackdropType="Mica"
|
||||||
d:DataContext="{d:DesignInstance vm:MainViewModel}"
|
d:DataContext="{d:DesignInstance vm:MainViewModel}"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d">
|
||||||
<StackPanel>
|
<Grid>
|
||||||
<TextBlock
|
<ui:NavigationView
|
||||||
HorizontalAlignment="Center"
|
ExpandedModeThresholdWidth="500"
|
||||||
FontSize="36"
|
IsTabStop="False"
|
||||||
Text="{Binding Message}" />
|
PaneDisplayMode="Left"
|
||||||
|
PaneTitle="设备管理系统"
|
||||||
|
IsSettingsVisible="False"
|
||||||
|
AlwaysShowHeader="True"
|
||||||
|
IsBackButtonVisible="Collapsed"
|
||||||
|
IsBackEnabled="False"
|
||||||
|
SelectionFollowsFocus="Disabled"
|
||||||
|
SelectionChanged="NavigationView_SelectionChanged">
|
||||||
|
|
||||||
<Border
|
<ui:NavigationView.MenuItems>
|
||||||
Width="100"
|
<ui:NavigationViewItem
|
||||||
Height="100"
|
Content="主页"
|
||||||
Background="Orange">
|
Tag="Home">
|
||||||
<i:Interaction.Behaviors>
|
<ui:NavigationViewItem.Icon>
|
||||||
<i:MouseDragElementBehavior />
|
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Home}" />
|
||||||
</i:Interaction.Behaviors>
|
</ui:NavigationViewItem.Icon>
|
||||||
</Border>
|
</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:NavigationViewItemHeader Content="Actions" />
|
||||||
|
<ui:NavigationViewItem
|
||||||
|
x:Name="SamplePage2Item"
|
||||||
|
Content="Menu Item2"
|
||||||
|
SelectsOnInvoked="True"
|
||||||
|
Tag="SamplePage2">
|
||||||
|
<ui:NavigationViewItem.Icon>
|
||||||
|
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Save}" />
|
||||||
|
</ui:NavigationViewItem.Icon>
|
||||||
|
</ui:NavigationViewItem>
|
||||||
|
<ui:NavigationViewItem
|
||||||
|
x:Name="SamplePage3Item"
|
||||||
|
Content="Menu Item3"
|
||||||
|
Tag="SamplePage3">
|
||||||
|
<ui:NavigationViewItem.Icon>
|
||||||
|
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Refresh}" />
|
||||||
|
</ui:NavigationViewItem.Icon>
|
||||||
|
</ui:NavigationViewItem>
|
||||||
|
</ui:NavigationView.MenuItems>
|
||||||
|
|
||||||
|
<ui:NavigationView.PaneCustomContent>
|
||||||
|
<ui:HyperlinkButton
|
||||||
|
x:Name="PaneHyperlink"
|
||||||
|
Margin="12,0"
|
||||||
|
Content="More info"
|
||||||
|
Visibility="Collapsed" />
|
||||||
|
</ui:NavigationView.PaneCustomContent>
|
||||||
|
|
||||||
|
|
||||||
|
<ui:NavigationView.AutoSuggestBox>
|
||||||
|
<ui:AutoSuggestBox AutomationProperties.Name="Search">
|
||||||
|
<ui:AutoSuggestBox.QueryIcon>
|
||||||
|
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Search}" />
|
||||||
|
</ui:AutoSuggestBox.QueryIcon>
|
||||||
|
</ui:AutoSuggestBox>
|
||||||
|
</ui:NavigationView.AutoSuggestBox>
|
||||||
|
|
||||||
|
|
||||||
|
<ui:NavigationView.PaneFooter>
|
||||||
|
<StackPanel
|
||||||
|
x:Name="FooterStackPanel"
|
||||||
|
Orientation="Vertical"
|
||||||
|
Visibility="Visible">
|
||||||
|
<ui:NavigationViewItem 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>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
</ui:NavigationView.PaneFooter>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
</ContentControl.Resources>
|
||||||
|
</ContentControl>
|
||||||
|
</ui:NavigationView>
|
||||||
|
</Grid>
|
||||||
</Window>
|
</Window>
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using iNKORE.UI.WPF.Modern.Controls;
|
||||||
using PMSWPF.ViewModels;
|
using PMSWPF.ViewModels;
|
||||||
|
|
||||||
namespace PMSWPF.Views
|
namespace PMSWPF.Views
|
||||||
@@ -8,10 +10,34 @@ namespace PMSWPF.Views
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class MainView : Window
|
public partial class MainView : Window
|
||||||
{
|
{
|
||||||
|
|
||||||
public MainView()
|
public MainView()
|
||||||
{
|
{
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
this.DataContext = new MainViewModel();
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void NavigationView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
|
||||||
|
{
|
||||||
|
NavigationViewItem? item = args.SelectedItem as NavigationViewItem;
|
||||||
|
MainViewModel mainViewModel = (MainViewModel)this.DataContext ;
|
||||||
|
switch (item.Tag)
|
||||||
|
{
|
||||||
|
case "Home":
|
||||||
|
mainViewModel.NavgateTo<HomeViewModel>();
|
||||||
|
break;
|
||||||
|
case "Devices":
|
||||||
|
mainViewModel.NavgateTo<DevicesViewModel>();
|
||||||
|
break;
|
||||||
|
case "DataTransform":
|
||||||
|
mainViewModel.NavgateTo<DataTransformViewModel>();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
mainViewModel.NavgateTo<HomeViewModel>();
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
<Window
|
|
||||||
x:Class="PMSWPF.Views.PlcListView"
|
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
|
||||||
xmlns:hc="https://handyorg.github.io/handycontrol"
|
|
||||||
xmlns:local="clr-namespace:PMSWPF.Views"
|
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
|
||||||
xmlns:vm="clr-namespace:PMSWPF.ViewModels"
|
|
||||||
Title="PlcListView"
|
|
||||||
Width="800"
|
|
||||||
Height="450"
|
|
||||||
d:DataContext="{d:DesignInstance vm:PlcListViewModel}"
|
|
||||||
mc:Ignorable="d">
|
|
||||||
<StackPanel>
|
|
||||||
<StackPanel Height="auto" />
|
|
||||||
<DataGrid
|
|
||||||
AutoGenerateColumns="False"
|
|
||||||
CanUserAddRows="True"
|
|
||||||
CanUserDeleteRows="True"
|
|
||||||
ItemsSource="{Binding PlcList}">
|
|
||||||
<DataGrid.Columns>
|
|
||||||
<DataGridTextColumn Binding="{Binding Path=Name}" Header="名称" />
|
|
||||||
|
|
||||||
</DataGrid.Columns>
|
|
||||||
</DataGrid>
|
|
||||||
|
|
||||||
</StackPanel>
|
|
||||||
</Window>
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Controls;
|
|
||||||
using System.Windows.Data;
|
|
||||||
using System.Windows.Documents;
|
|
||||||
using System.Windows.Input;
|
|
||||||
using System.Windows.Media;
|
|
||||||
using System.Windows.Media.Imaging;
|
|
||||||
using System.Windows.Shapes;
|
|
||||||
|
|
||||||
namespace PMSWPF.Views
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// PlcListView.xaml 的交互逻辑
|
|
||||||
/// </summary>
|
|
||||||
public partial class PlcListView : Window
|
|
||||||
{
|
|
||||||
public PlcListView()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user