KWD hai 3 meses
pai
achega
f685a0e6e4

+ 7 - 6
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"
@@ -37,14 +38,14 @@
                 <TextBlock Text="{Binding ElementName=dg_params,Path=Items.Count}" VerticalAlignment="Center" Margin="5,0" />
             </StackPanel>
         </StackPanel>
-        
+
         <DataGrid x:Name="dg_params" Grid.Row="1" AutoGenerateColumns="False"
                   CanUserAddRows="False"
                   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 编号}"
@@ -72,6 +73,6 @@
                                     Binding="{Binding Param5, Mode=TwoWay}" />
             </DataGrid.Columns>
         </DataGrid>
-        
+
     </Grid>
 </UserControl>

+ 10 - 4
TeamAAS-VM/Controls/ParameterEdit.xaml.cs

@@ -29,7 +29,6 @@ namespace TeamAAS_VP.Controls
         public ParameterEdit()
         {
             InitializeComponent();
-            DataContext = this;
         }
 
         private ProductGlobalParam _SelectParam;
@@ -37,7 +36,7 @@ namespace TeamAAS_VP.Controls
         public ProductGlobalParam SelectParam
         {
             get { return _SelectParam; }
-            set { SetProperty(ref _SelectParam,value); }
+            set { SetProperty(ref _SelectParam, value); }
         }
 
 
@@ -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>

+ 0 - 2
TeamAAS-VM/Core/Management.cs

@@ -6,8 +6,6 @@ using NPOI.SS.Formula.Eval;
 using NPOI.SS.Formula.Functions;
 using NPOI.Util;
 using Org.BouncyCastle.Ocsp;
-
-
 //using ICSharpCode.SharpZipLib.Zip;
 using Prism.Events;
 using Prism.Ioc;

+ 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;
+                        });
                     }
                 }
             }

+ 7 - 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,12 @@ 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 - 14
TeamAAS-VM/Views/Product/ProductParams.xaml.cs

@@ -13,20 +13,6 @@ namespace TeamAAS_VP.Views.Product
         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;
-            }
         }
     }
 }