添加了变量表的停用和启用功能,并优化了添加变量表和添加设备的逻辑
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
<DockPanel>
|
||||
<ui:ToggleSwitch DockPanel.Dock="Right"
|
||||
Margin="20 0 0 0 "
|
||||
IsOn="{Binding IsActive}"
|
||||
IsOn="{Binding IsFirstLoad}"
|
||||
OffContent="停止"
|
||||
OnContent="启动" />
|
||||
<TextBlock FontSize="24"
|
||||
|
||||
@@ -28,8 +28,7 @@
|
||||
</ContextMenu>
|
||||
<DataTemplate x:Key="NavigationViewMenuItem"
|
||||
DataType="{x:Type mo:MenuBean}">
|
||||
<ui:NavigationViewItem
|
||||
Content="{Binding Name}"
|
||||
<ui:NavigationViewItem Content="{Binding Name}"
|
||||
MenuItemsSource="{Binding Items }">
|
||||
<ui:NavigationViewItem.Icon>
|
||||
<ui:FontIcon Glyph="{Binding Icon}" />
|
||||
@@ -50,6 +49,7 @@
|
||||
MenuItemsSource="{Binding Menus}"
|
||||
MenuItemTemplate="{StaticResource NavigationViewMenuItem}"
|
||||
SelectionChanged="NavigationView_SelectionChanged">
|
||||
|
||||
|
||||
<ui:NavigationView.AutoSuggestBox>
|
||||
<ui:AutoSuggestBox AutomationProperties.Name="Search">
|
||||
@@ -86,7 +86,7 @@
|
||||
</DataTemplate>
|
||||
<!-- 设备变量页 -->
|
||||
<DataTemplate DataType="{x:Type vm:VariableTableViewModel}">
|
||||
<local:VariableTableView />
|
||||
<local:VariableTableView DataContext="{Binding }"/>
|
||||
</DataTemplate>
|
||||
</ContentControl.Resources>
|
||||
</ContentControl>
|
||||
|
||||
@@ -8,29 +8,43 @@
|
||||
xmlns:vm="clr-namespace:PMSWPF.ViewModels"
|
||||
xmlns:controls="http://schemas.inkore.net/lib/ui/wpf/modern"
|
||||
mc:Ignorable="d"
|
||||
Loaded="VariableTableView_OnLoaded"
|
||||
d:DataContext="{d:DesignInstance vm:VariableTableViewModel}"
|
||||
d:DesignHeight="600" d:DesignWidth="800">
|
||||
d:DesignHeight="600"
|
||||
d:DesignWidth="800">
|
||||
<UserControl.Resources>
|
||||
<!-- 标签字体的样式 -->
|
||||
<Style TargetType="TextBlock" x:Key="VarTableLabelStyle">
|
||||
<Setter Property="Foreground" Value="#555" />
|
||||
<Setter Property="FontSize" Value="20" />
|
||||
<Style TargetType="TextBlock"
|
||||
x:Key="VarTableLabelStyle">
|
||||
<Setter Property="Foreground"
|
||||
Value="#555" />
|
||||
<Setter Property="FontSize"
|
||||
Value="16" />
|
||||
<Setter Property="VerticalAlignment"
|
||||
Value="Center" />
|
||||
</Style>
|
||||
<!-- 值字体的样式 -->
|
||||
<Style TargetType="TextBlock" x:Key="VarTableValueStyle">
|
||||
<Setter Property="FontWeight" Value="Bold" />
|
||||
<Setter Property="FontSize" Value="16" />
|
||||
<Setter Property="MinWidth" Value="120" />
|
||||
<Setter Property="VerticalAlignment" Value="Center" />
|
||||
<Style TargetType="TextBlock"
|
||||
x:Key="VarTableValueStyle">
|
||||
<Setter Property="FontWeight"
|
||||
Value="Bold" />
|
||||
<Setter Property="FontSize"
|
||||
Value="16" />
|
||||
<Setter Property="MinWidth"
|
||||
Value="100" />
|
||||
<Setter Property="VerticalAlignment"
|
||||
Value="Center" />
|
||||
</Style>
|
||||
</UserControl.Resources>
|
||||
|
||||
<DockPanel>
|
||||
|
||||
<ikw:SimpleStackPanel Margin="10" DockPanel.Dock="Top">
|
||||
<DockPanel>
|
||||
|
||||
<ikw:SimpleStackPanel Margin="10"
|
||||
DockPanel.Dock="Top">
|
||||
<!-- 操作菜单 -->
|
||||
<controls:CommandBar x:Name="PrimaryCommandBar"
|
||||
DefaultLabelPosition="Right" IsOpen="False">
|
||||
DefaultLabelPosition="Right"
|
||||
IsOpen="False">
|
||||
<ui:AppBarButton x:Name="AddButton"
|
||||
Command="{Binding AddDeviceCommand}"
|
||||
Label="Add">
|
||||
@@ -53,24 +67,40 @@
|
||||
</ui:AppBarButton>
|
||||
<ui:CommandBar.SecondaryCommands>
|
||||
<ui:AppBarButton x:Name="SettingsButton"
|
||||
|
||||
Icon="Setting" Label="Settings" />
|
||||
Icon="Setting"
|
||||
Label="Settings" />
|
||||
</ui:CommandBar.SecondaryCommands>
|
||||
</controls:CommandBar>
|
||||
<!-- 变量表的名称描述等信息 -->
|
||||
<ikw:SimpleStackPanel Margin="10" Orientation="Horizontal" Spacing="10">
|
||||
<TextBlock Style="{StaticResource VarTableLabelStyle}" Text="变量表名称:" />
|
||||
<TextBlock Style="{StaticResource VarTableValueStyle}" Text="{Binding VariableTable.Name}" />
|
||||
<TextBlock Style="{StaticResource VarTableLabelStyle}" Text="变量表描述:" />
|
||||
<TextBlock Style="{StaticResource VarTableValueStyle}" Text="{Binding VariableTable.Description}" />
|
||||
<TextBlock Style="{StaticResource VarTableLabelStyle}" Text="所属设备:" />
|
||||
<TextBlock Style="{StaticResource VarTableValueStyle}" Text="默认变量表" />
|
||||
<ikw:SimpleStackPanel Margin="5"
|
||||
Orientation="Horizontal"
|
||||
Spacing="10">
|
||||
<ui:ToggleSwitch
|
||||
OnContent="启用"
|
||||
OffContent="停用"
|
||||
Toggled="OnIsActiveChanged"
|
||||
FontSize="16"
|
||||
IsOn="{Binding VariableTable.IsActive}"/>
|
||||
<TextBlock Style="{StaticResource VarTableLabelStyle}"
|
||||
Text="变量表名称:" />
|
||||
<TextBlock Style="{StaticResource VarTableValueStyle}"
|
||||
Text="{Binding VariableTable.Name}" />
|
||||
<TextBlock Style="{StaticResource VarTableLabelStyle}"
|
||||
Text="变量表描述:" />
|
||||
<TextBlock Style="{StaticResource VarTableValueStyle}"
|
||||
Text="{Binding VariableTable.Description}" />
|
||||
<TextBlock Style="{StaticResource VarTableLabelStyle}"
|
||||
Text="所属设备:" />
|
||||
<TextBlock Style="{StaticResource VarTableValueStyle}"
|
||||
Text="{Binding VariableTable.Device.Name}" />
|
||||
|
||||
|
||||
</ikw:SimpleStackPanel>
|
||||
|
||||
|
||||
</ikw:SimpleStackPanel>
|
||||
|
||||
<DataGrid Margin="10" />
|
||||
</DockPanel>
|
||||
</DockPanel>
|
||||
|
||||
</UserControl>
|
||||
@@ -1,14 +1,44 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using iNKORE.UI.WPF.Modern.Controls;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PMSWPF.Helper;
|
||||
using PMSWPF.ViewModels;
|
||||
|
||||
namespace PMSWPF.Views;
|
||||
|
||||
public partial class VariableTableView : UserControl
|
||||
{
|
||||
public bool IsLoadCompletion;
|
||||
|
||||
public VariableTableView()
|
||||
{
|
||||
InitializeComponent();
|
||||
DataContext = App.Current.Services.GetRequiredService<VariableTableViewModel>();
|
||||
IsLoadCompletion = false;
|
||||
}
|
||||
|
||||
|
||||
private async void OnIsActiveChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var _viewModel = (VariableTableViewModel)this.DataContext;
|
||||
// 判断如果没有加载完成就跳过,防止ToggleSwtich加载的时候触发
|
||||
if (!_viewModel.IsLoadCompletion || !IsLoadCompletion)
|
||||
return;
|
||||
|
||||
ToggleSwitch toggleSwitch = (ToggleSwitch)sender;
|
||||
await _viewModel.OnIsActiveChanged(toggleSwitch.IsOn);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
NotificationHelper.ShowMessage($"修改变量表启用,停用时发生了错误:{exception.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private void VariableTableView_OnLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
IsLoadCompletion = true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user