فهرست منبع

优化切换模板,与一些架构方面调整

KWD 3 ماه پیش
والد
کامیت
4b66d40928

+ 22 - 22
TeamAAS-VM/App.xaml

@@ -1,35 +1,37 @@
-<prism:PrismApplication x:Class="TeamAAS_VP.App"
-                        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
-                        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-                        xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
-                        xmlns:c="clr-namespace:TeamAAS_VP.ValueConverter"
-                        xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf;assembly=MaterialDesignThemes.Wpf"
-                        xmlns:local="clr-namespace:TeamAAS_VP"
-                        xmlns:prism="http://prismlibrary.com/">
+<prism:PrismApplication
+    x:Class="TeamAAS_VP.App"
+    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+    xmlns:c="clr-namespace:TeamAAS_VP.ValueConverter"
+    xmlns:local="clr-namespace:TeamAAS_VP"
+    xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
+    xmlns:prism="http://prismlibrary.com/"
+    xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf;assembly=MaterialDesignThemes.Wpf">
     <Application.Resources>
         <ResourceDictionary>
             <ResourceDictionary.MergedDictionaries>
-                
+
                 <!--<ResourceDictionary Source="Resources/Languages1/Chinese.xaml" />-->
                 <ResourceDictionary Source="Resources\Styles\DefaultColors.xaml" />
 
                 <ResourceDictionary Source="Resources/FontSize/DefaultFontSize.xaml" />
 
-                <materialDesign:BundledTheme BaseTheme="Inherit"
-                                             PrimaryColor="DeepPurple"
-                                             SecondaryColor="Purple" />
-                <!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
+                <materialDesign:BundledTheme
+                    BaseTheme="Inherit"
+                    PrimaryColor="DeepPurple"
+                    SecondaryColor="Purple" />
+                <!--  MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive!  -->
                 <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
                 <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
-                <!-- Theme setting -->
+                <!--  Theme setting  -->
                 <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/Light.Blue.xaml" />
-                
-                <!--MaterialDesign-->
+
+                <!--  MaterialDesign  -->
                 <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
                 <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesign3.Defaults.xaml" />
                 <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
                 <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Secondary/MaterialDesignColor.Lime.xaml" />
-                <!--MaterialDesign-->
+                <!--  MaterialDesign  -->
 
                 <ResourceDictionary Source="pack://application:,,,/ICSharpCode.AvalonEdit;component/themes/generic.xaml" />
             </ResourceDictionary.MergedDictionaries>
@@ -38,12 +40,10 @@
             <c:StringFormatConverter x:Key="StringFormatConverter" />
             <c:InvertBooleanConverter x:Key="InvertBooleanConverter" />
             <c:ObjectToVisibilityConverter x:Key="ObjectToVisibilityConverter" />
-            <c:ObjectToVisibilityConverter x:Key="ObjectToCollapsedConverter"
-                                           Invert="True" />
+            <c:ObjectToVisibilityConverter x:Key="ObjectToCollapsedConverter" Invert="True" />
             <c:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
-            <c:BooleanToVisibilityConverter x:Key="BooleanToCollapsedConverter"
-                                            Invert="True" />
+            <c:BooleanToVisibilityConverter x:Key="BooleanToCollapsedConverter" Invert="True" />
         </ResourceDictionary>
-        
+
     </Application.Resources>
 </prism:PrismApplication>

+ 5 - 4
TeamAAS-VM/Controls/ParameterEdit.xaml

@@ -1,4 +1,5 @@
 <UserControl x:Class="TeamAAS_VP.Controls.ParameterEdit"
+             x:Name="root"
              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"
@@ -27,9 +28,9 @@
             <StackPanel Orientation="Horizontal">
                 <Button Content="{lex:Loc 增加}"
                         Margin="10"
-                        Command="{Binding AddCommand}" />
+                        Command="{Binding AddCommand, ElementName=root}" />
                 <Button Content="{lex:Loc 移除}"
-                        Command="{Binding RemoveCommand}" 
+                        Command="{Binding RemoveCommand, ElementName=root}"
                         CommandParameter="{Binding ElementName=dg_params,Path=SelectedItem}"/>
                 <TextBlock Text="{lex:Loc 总数,Converter={StaticResource StringFormatConverter},ConverterParameter='{}{0}: '}"
                            VerticalAlignment="Center"
@@ -43,8 +44,8 @@
                   ColumnWidth="*"
                   SelectionUnit="FullRow"
                   SelectionMode="Single"
-                  SelectedItem="{Binding SelectParam}"
-                  ItemsSource="{Binding GlobalParamListCollection}"
+                  SelectedItem="{Binding SelectParam, ElementName=root}"
+                  ItemsSource="{Binding GlobalParamListCollection, ElementName=root}"
                   HeadersVisibility="All">
             <DataGrid.Columns>
                 <DataGridTextColumn Header="{lex:Loc 编号}"

+ 9 - 3
TeamAAS-VM/Controls/ParameterEdit.xaml.cs

@@ -29,7 +29,6 @@ namespace TeamAAS_VP.Controls
         public ParameterEdit()
         {
             InitializeComponent();
-            DataContext = this;
         }
 
         private ProductGlobalParam _SelectParam;
@@ -49,7 +48,7 @@ namespace TeamAAS_VP.Controls
                 nameof(GlobalParamListCollection),
                 typeof(ObservableCollection<ProductGlobalParam>),
                 typeof(ParameterEdit),
-                new PropertyMetadata(new ObservableCollection<ProductGlobalParam>()));
+                new PropertyMetadata(null));
 
         /// <summary>
         /// 公开可绑定属性
@@ -70,6 +69,8 @@ namespace TeamAAS_VP.Controls
 
         void ExecuteRemoveCommand(ProductGlobalParam param)
         {
+            if (param == null || GlobalParamListCollection == null) return;
+
             GlobalParamListCollection.Remove(param);
             for (int i = 0; i < GlobalParamListCollection.Count; i++)
             {
@@ -79,7 +80,12 @@ namespace TeamAAS_VP.Controls
 
         void ExecuteAddCommand()
         {
-            GlobalParamListCollection.Add(new ProductGlobalParam() { Number= GlobalParamListCollection .Count});
+            if (GlobalParamListCollection == null)
+            {
+                GlobalParamListCollection = new ObservableCollection<ProductGlobalParam>();
+            }
+
+            GlobalParamListCollection.Add(new ProductGlobalParam() { Number= GlobalParamListCollection.Count});
         }
         #region 属性通知
         /// <summary>

+ 7 - 6
TeamAAS-VM/Resources/FontSize/DefaultFontSize.xaml

@@ -1,17 +1,18 @@
-<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
-                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-                    xmlns:sys="clr-namespace:System;assembly=mscorlib">
-    <!--标题-->
+<ResourceDictionary
+    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+    xmlns:sys="clr-namespace:System;assembly=mscorlib">
+    <!--  标题  -->
     <sys:Double x:Key="Font.Size.Title1">34</sys:Double>
     <sys:Double x:Key="Font.Size.Title2">20</sys:Double>
     <sys:Double x:Key="Font.Size.Title3">18</sys:Double>
     <sys:Double x:Key="Font.Size.Title4">16</sys:Double>
-    <!--正文-->
+    <!--  正文  -->
     <sys:Double x:Key="Font.Size.Body1">18</sys:Double>
     <sys:Double x:Key="Font.Size.Body2">16</sys:Double>
     <sys:Double x:Key="Font.Size.Body3">14</sys:Double>
     <sys:Double x:Key="Font.Size.Body4">12</sys:Double>
-    <!--标注-->
+    <!--  标注  -->
     <sys:Double x:Key="Font.Size.Captions1">16</sys:Double>
     <sys:Double x:Key="Font.Size.Captions2">14</sys:Double>
     <sys:Double x:Key="Font.Size.Captions3">12</sys:Double>

+ 7 - 14
TeamAAS-VM/Resources/Styles/DefaultColors.xaml

@@ -1,15 +1,8 @@
-<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
-                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
-    <SolidColorBrush x:Key="DefaultBackground"
-                     Color="#424242" />
-    <SolidColorBrush x:Key="DefaultFore"
-                     Color="#F0F0F0" />
-    <SolidColorBrush x:Key="DefaultNavigationCheckedBackground"
-                     Color="Transparent" />
-    <SolidColorBrush x:Key="DefaultNavigationCheckedFore"
-                     Color="#50ac52" />
-    <SolidColorBrush x:Key="DefaultNavigationUnCheckedBackground"
-                     Color="Transparent" />
-    <SolidColorBrush x:Key="DefaultNavigationUnCheckedFore"
-                     Color="#424242" />
+<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
+    <SolidColorBrush x:Key="DefaultBackground" Color="#424242" />
+    <SolidColorBrush x:Key="DefaultFore" Color="#F0F0F0" />
+    <SolidColorBrush x:Key="DefaultNavigationCheckedBackground" Color="Transparent" />
+    <SolidColorBrush x:Key="DefaultNavigationCheckedFore" Color="#50ac52" />
+    <SolidColorBrush x:Key="DefaultNavigationUnCheckedBackground" Color="Transparent" />
+    <SolidColorBrush x:Key="DefaultNavigationUnCheckedFore" Color="#424242" />
 </ResourceDictionary>

+ 8 - 1
TeamAAS-VM/Services/ProductService.cs

@@ -541,6 +541,8 @@ namespace TeamAAS_VP.Services
             {
                 foreach (var prc in camera.ProcedureModels)
                 {
+                    if (prc.ToolBlock != null) continue;
+
                     string prcPath = Path.Combine(dir, camera.Camera, prc.Name + ".vpp");
 
                     prc.ToolBlock = _vppCache.GetOrAdd(prcPath, path =>
@@ -576,9 +578,14 @@ namespace TeamAAS_VP.Services
                 {
                     foreach (var prc in camera.ProcedureModels)
                     {
+                        if (prc.ToolBlock != null) continue;
+
                         string prcPath = Path.Combine(dir, camera.Camera, prc.Name + ".vpp");
                         temp = prcPath;
-                        prc.ToolBlock = CogSerializer.LoadObjectFromFile(prcPath) as CogToolBlock;
+                        prc.ToolBlock = _vppCache.GetOrAdd(prcPath, path =>
+                        {
+                            return CogSerializer.LoadObjectFromFile(path) as CogToolBlock;
+                        });
                     }
                 }
             }

+ 6 - 0
TeamAAS-VM/ViewModels/Product/ProductParamsViewModel.cs

@@ -18,6 +18,7 @@ using TeamAAS_VP.Core;
 using TeamAAS_VP.Events;
 using TeamAAS_VP.Interfaces;
 using TeamAAS_VP.Models;
+using TeamAAS_VP.Models.Product;
 using TeamAAS_VP.Resources.Languages;
 using TeamAAS_VP.Services;
 
@@ -305,6 +306,11 @@ namespace TeamAAS_VP.ViewModels.Product
             try
             {
                 SelectProduct = navigationContext.Parameters.GetValue<ProductModel>("SelectProduct");
+                if (SelectProduct.GlobalParamListCollection == null)
+                {
+                    SelectProduct.GlobalParamListCollection = new ObservableCollection<ProductGlobalParam>();
+                }
+
                 ProcedureModels = new ObservableCollection<ProcedureModel>();
                 foreach (var item in SelectProduct.CameraProcedures)
                 {

+ 0 - 17
TeamAAS-VM/Views/Product/ProductParams.xaml.cs

@@ -1,6 +1,4 @@
 using System.Windows.Controls;
-using TeamAAS_VP.Models.Product;
-using TeamAAS_VP.ViewModels.Product;
 
 namespace TeamAAS_VP.Views.Product
 {
@@ -9,24 +7,9 @@ namespace TeamAAS_VP.Views.Product
     /// </summary>
     public partial class ProductParams : UserControl
     {
-        ProductParamsViewModel VM;
         public ProductParams()
         {
             InitializeComponent();
-            VM = DataContext as ProductParamsViewModel;
-            this.Loaded += ProductParams_Loaded;
-        }
-
-        private void ProductParams_Loaded(object sender, System.Windows.RoutedEventArgs e)
-        {
-            if (VM != null)
-            {
-                if (VM.SelectProduct.GlobalParamListCollection == null)
-                {
-                    VM.SelectProduct.GlobalParamListCollection = new System.Collections.ObjectModel.ObservableCollection<ProductGlobalParam>();
-                }
-                this.parameterEdit.GlobalParamListCollection = VM.SelectProduct.GlobalParamListCollection;
-            }
         }
     }
 }