瀏覽代碼

修改测试

ltwork 1 年之前
父節點
當前提交
27498c5bab

+ 1 - 1
BlankApp1/BlankApp1/App.config

@@ -6,7 +6,7 @@
 	    <!--1表示欧姆龙PLC,2表示为三菱PLC-->
 	    <!--1表示欧姆龙PLC,2表示为三菱PLC-->
 		<add key="PLCType" value="1"/>
 		<add key="PLCType" value="1"/>
 		<add key="PLCIp" value="127.0.0.1"/>
 		<add key="PLCIp" value="127.0.0.1"/>
-		<add key="PLCPort" value="6000"/>
+		<add key="PLCPort" value="9600"/>
 		<add key="DelayTime" value="20"/>
 		<add key="DelayTime" value="20"/>
 		<add key="LongDelayTime" value="60"/>
 		<add key="LongDelayTime" value="60"/>
 		<add key="AutoUpdateServer" value="127.0.0.1"/>
 		<add key="AutoUpdateServer" value="127.0.0.1"/>

+ 74 - 3
BlankApp1/BlankApp1/ViewModels/BusinessManageViewModel/AutoTestViewModel.cs

@@ -75,6 +75,8 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
             InConList = new ObservableCollection<BasPlcItemConfigDto>();
             InConList = new ObservableCollection<BasPlcItemConfigDto>();
             OutConList = new ObservableCollection<BasPlcItemConfigDto>();
             OutConList = new ObservableCollection<BasPlcItemConfigDto>();
             GetConfigOption();
             GetConfigOption();
+            ReadPreTask();//读取前置项线程
+            m2.Set();
 
 
         }
         }
         /// <summary>
         /// <summary>
@@ -84,8 +86,10 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         private void Unload()
         private void Unload()
         {
         {
            
            
-             m.Reset();  //阻塞线程
-             RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
+            m.Reset();  //阻塞线程
+            tokensource.Cancel(); //取消自动检测线程
+            tokensource2.Cancel(); //取消读取前置项的线程
+            RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
         }
         }
 
 
         private void Cancel(object obj)
         private void Cancel(object obj)
@@ -143,6 +147,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                 globalSchDetailId = id;
                 globalSchDetailId = id;
                 selctStartDetailId = id;
                 selctStartDetailId = id;
                 GetDetailInfo(id);
                 GetDetailInfo(id);
+                m2.Set();  //继续线程(读取前置项)
             }
             }
         }
         }
 
 
@@ -313,6 +318,58 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         #endregion
         #endregion
 
 
         #region 私有发方法
         #region 私有发方法
+
+        CancellationTokenSource tokensource2 = new CancellationTokenSource(); //声明令牌
+        ManualResetEvent m2 = new ManualResetEvent(true); //实例化阻塞事件
+        private void ReadPreTask()
+        {
+            CancellationToken cancellationToken2 = tokensource2.Token;
+            Task.Run(async () =>
+            {
+                while (true)
+                {
+                    if (cancellationToken2.IsCancellationRequested)
+                    {
+                        return;
+                    }
+                    m2.WaitOne(); //当m等于true,才会往下执行,否则一直在此等待
+                    System.Windows.Application.Current.Dispatcher.Invoke((delegate
+                    {
+                        foreach (var item in BeforeConList.OrderBy(x => x.Id))
+                        {
+                            string plcAddress = item.PlcAddress;
+                            string plcAddType = item.PlcAddType;
+                            string plcValue = item.PlcValue;
+
+                            switch (plcAddType)
+                            {
+                                case "bool":
+                                    string readResult = PLCConnectionFactory.CreatePLCCont().ReadPlcObject(plcAddress, VarType.Bit);
+                                    ///实时值记录
+
+                                    item.RealValue = readResult;
+                                    item.TestTime = DateTime.Now;
+
+                                    break;
+                                case "word":
+                                    string readResult2 = PLCConnectionFactory.CreatePLCCont().ReadPlcObject(plcAddress, VarType.Word);
+                                    ///实时值记录
+
+                                    item.RealValue = readResult2;
+                                    item.TestTime = DateTime.Now;
+
+                                    break;
+
+                            }
+
+                        }
+                    }));
+
+                    await Task.Delay(2000);
+                }
+
+            }, cancellationToken2);//绑定令牌到多线程;
+        }
         /// <summary>
         /// <summary>
         /// 增加或更新测试记录
         /// 增加或更新测试记录
         /// </summary>
         /// </summary>
@@ -614,7 +671,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         /// <param name="obj"></param>
         /// <param name="obj"></param>
         private  void Start()
         private  void Start()
         {
         {
-          
+            m2.Reset();  //阻塞线程(不再读取前置项)
             CancellationToken cancellationToken = tokensource.Token;
             CancellationToken cancellationToken = tokensource.Token;
             StartEnalbe = false;
             StartEnalbe = false;
             Task.Run(async() =>  //模拟耗时任务
             Task.Run(async() =>  //模拟耗时任务
@@ -832,6 +889,20 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                         }
                         }
                         break;
                         break;
                     case "word":
                     case "word":
+                        string readResult2 = PLCConnectionFactory.CreatePLCCont().ReadPlcObject(plcAddress, VarType.Word);
+                        ///实时值记录
+
+                        item.RealValue = readResult2;
+                        item.TestTime = DateTime.Now;
+                        if (readResult2.Trim() == plcValue?.Trim())
+                        {
+                            item.TestResult = "通过";
+                            countCond++;
+                        }
+                        else
+                        {
+                            item.TestResult = "不通过";
+                        }
                         break;
                         break;
 
 
                 }
                 }

+ 88 - 6
BlankApp1/BlankApp1/ViewModels/BusinessManageViewModel/ManualTestViewModel.cs

@@ -19,6 +19,7 @@ using System.Configuration;
 using System.Linq;
 using System.Linq;
 using System.Linq.Expressions;
 using System.Linq.Expressions;
 using System.Text;
 using System.Text;
+using System.Threading;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 using System.Windows;
 using System.Windows;
 using WPFDevelopers.Controls.Runtimes.Shell32;
 using WPFDevelopers.Controls.Runtimes.Shell32;
@@ -70,14 +71,22 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
             PreviousCommand = new DelegateCommand<object>(Previous);
             PreviousCommand = new DelegateCommand<object>(Previous);
             NextCommand = new DelegateCommand<object>(Next);
             NextCommand = new DelegateCommand<object>(Next);
             DoneCommand = new DelegateCommand<object>(Done);
             DoneCommand = new DelegateCommand<object>(Done);
+            UnLoadCommand = new DelegateCommand(Unload);
             ItemChangeCommand = new DelegateCommand(ItemChange);
             ItemChangeCommand = new DelegateCommand(ItemChange);
             ResetCommand = new DelegateCommand(Reset);
             ResetCommand = new DelegateCommand(Reset);
             BeforeConList = new ObservableCollection<BasPlcItemConfigDto>();
             BeforeConList = new ObservableCollection<BasPlcItemConfigDto>();
             InConList = new ObservableCollection<BasPlcItemConfigDto>();
             InConList = new ObservableCollection<BasPlcItemConfigDto>();
             OutConList = new ObservableCollection<BasPlcItemConfigDto>();
             OutConList = new ObservableCollection<BasPlcItemConfigDto>();
             GetConfigOption();
             GetConfigOption();
-           
+            ReadPreTask();//读取前置项线程
+            m2.Set();
+        }
+
+        private void Unload()
+        {
+            tokensource.Cancel(); //取消读取前置项的线程
         }
         }
+
         /// <summary>
         /// <summary>
         /// 选中测试项
         /// 选中测试项
         /// </summary>
         /// </summary>
@@ -91,6 +100,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                 globalSchDetailId = id;
                 globalSchDetailId = id;
                 globalSort = findDtlMsg.sort;
                 globalSort = findDtlMsg.sort;
                 GetDetailInfo(id);
                 GetDetailInfo(id);
+                m2.Set();  //继续线程(读取前置项)
             }
             }
         }
         }
         /// <summary>
         /// <summary>
@@ -289,6 +299,57 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         #endregion
         #endregion
 
 
         #region 私有发方法
         #region 私有发方法
+        CancellationTokenSource tokensource = new CancellationTokenSource(); //声明令牌
+        ManualResetEvent m2 = new ManualResetEvent(true); //实例化阻塞事件
+        private void ReadPreTask()
+        {
+            CancellationToken cancellationToken = tokensource.Token;
+            Task.Run(async()=>
+            {
+                while(true)
+                {
+                    if (cancellationToken.IsCancellationRequested)
+                    {
+                        return;
+                    }
+                    m2.WaitOne(); //当m等于true,才会往下执行,否则一直在此等待
+                    System.Windows.Application.Current.Dispatcher.Invoke((delegate
+                    {
+                        foreach (var item in BeforeConList.OrderBy(x => x.Id))
+                        {
+                            string plcAddress = item.PlcAddress;
+                            string plcAddType = item.PlcAddType;
+                            string plcValue = item.PlcValue;
+
+                            switch (plcAddType)
+                            {
+                                case "bool":
+                                    string readResult = PLCConnectionFactory.CreatePLCCont().ReadPlcObject(plcAddress, VarType.Bit);
+                                    ///实时值记录
+
+                                    item.RealValue = readResult;
+                                    item.TestTime = DateTime.Now;
+
+                                    break;
+                                case "word":
+                                    string readResult2 = PLCConnectionFactory.CreatePLCCont().ReadPlcObject(plcAddress, VarType.Word);
+                                    ///实时值记录
+
+                                    item.RealValue = readResult2;
+                                    item.TestTime = DateTime.Now;
+
+                                    break;
+
+                            }
+
+                        }
+                    }));
+                   
+                    await Task.Delay(2000);
+                }
+
+            }, cancellationToken);//绑定令牌到多线程;
+        }
         /// <summary>
         /// <summary>
         /// 增加或更新测试记录
         /// 增加或更新测试记录
         /// </summary>
         /// </summary>
@@ -587,12 +648,14 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         private void Done(object obj)
         private void Done(object obj)
         {
         {
             endTime = DateTime.Now;
             endTime = DateTime.Now;
+            tokensource.Cancel(); //取消读取前置项的线程
             RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
             RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
       
       
         }
         }
 
 
         private void Next(object obj)
         private void Next(object obj)
         {
         {
+            m2.Set();  //继续线程(读取前置项)
             StepIndex = 0;
             StepIndex = 0;
             long maxSort = allSchDtlsById.Select(x => x.sort).Max();
             long maxSort = allSchDtlsById.Select(x => x.sort).Max();
             ///查找方案下的所有方案明细,并排序,
             ///查找方案下的所有方案明细,并排序,
@@ -653,6 +716,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
 
 
         private void Previous(object obj)
         private void Previous(object obj)
         {
         {
+            m2.Set();  //继续线程(读取前置项)
             StepIndex = 0;
             StepIndex = 0;
             int maxSort = allSchDtlsById.Select(x => x.sort).Max();
             int maxSort = allSchDtlsById.Select(x => x.sort).Max();
             if(maxSort!=0)
             if(maxSort!=0)
@@ -715,8 +779,8 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         /// <param name="obj"></param>
         /// <param name="obj"></param>
         private async  void Start(object obj)
         private async  void Start(object obj)
         {
         {
-         
-   
+
+            m2.Reset();  //阻塞线程(不再读取前置项)
             StartEnalbe = false;
             StartEnalbe = false;
             _logger.LogInformation($"开始手动测试。方案名{ScheduleName},测试项{TestName}");
             _logger.LogInformation($"开始手动测试。方案名{ScheduleName},测试项{TestName}");
             SendLogToDis($"开始手动测试。方案名{ScheduleName},测试项{TestName}");
             SendLogToDis($"开始手动测试。方案名{ScheduleName},测试项{TestName}");
@@ -739,6 +803,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
             {
             {
                 MessageBoxResult boxResult = MessageBox.Show("前置项条件不满足,请确认前置条件!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
                 MessageBoxResult boxResult = MessageBox.Show("前置项条件不满足,请确认前置条件!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
                 StartEnalbe = true;
                 StartEnalbe = true;
+                m2.Set();  //继续线程(读取前置项)
                 return;
                 return;
                 
                 
             }
             }
@@ -870,6 +935,20 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                         }
                         }
                         break;
                         break;
                     case "word":
                     case "word":
+                        string readResult2 = PLCConnectionFactory.CreatePLCCont().ReadPlcObject(plcAddress, VarType.Word);
+                        ///实时值记录
+
+                        item.RealValue = readResult2;
+                        item.TestTime = DateTime.Now;
+                        if (readResult2.Trim() == plcValue?.Trim())
+                        {
+                            item.TestResult = "通过";
+                            countCond++;
+                        }
+                        else
+                        {
+                            item.TestResult = "不通过";
+                        }
                         break;
                         break;
 
 
                 }
                 }
@@ -1327,10 +1406,10 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         /// </summary>
         /// </summary>
         private void Close()
         private void Close()
         {
         {
-            MessageBoxResult boxResult = MessageBox.Show("确认退出自动测试", "确认", MessageBoxButton.OKCancel, MessageBoxImage.Information);
+            MessageBoxResult boxResult = MessageBox.Show("确认退出测试", "确认", MessageBoxButton.OKCancel, MessageBoxImage.Information);
             if (boxResult == MessageBoxResult.OK)
             if (boxResult == MessageBoxResult.OK)
             {
             {
-              
+                tokensource.Cancel(); //取消读取前置项的线程
                 RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
                 RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
             }
             }
             
             
@@ -1389,7 +1468,10 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         public DelegateCommand<object> DoneCommand { set; get; }
         public DelegateCommand<object> DoneCommand { set; get; }
         public DelegateCommand ItemChangeCommand { set; get; }
         public DelegateCommand ItemChangeCommand { set; get; }
         public DelegateCommand ResetCommand { set; get; }
         public DelegateCommand ResetCommand { set; get; }
-        
+
+        public DelegateCommand UnLoadCommand { set; get; }
+
+
         #endregion
         #endregion
         #region 变量绑定
         #region 变量绑定
         /// <summary>
         /// <summary>

+ 97 - 16
BlankApp1/BlankApp1/ViewModels/BusinessManageViewModel/RetryTestViewModel.cs

@@ -17,6 +17,7 @@ using System.ComponentModel;
 using System.Configuration;
 using System.Configuration;
 using System.Linq;
 using System.Linq;
 using System.Text;
 using System.Text;
+using System.Threading;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 using System.Windows;
 using System.Windows;
 
 
@@ -65,26 +66,17 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
             NextCommand = new DelegateCommand<object>(Next);
             NextCommand = new DelegateCommand<object>(Next);
             DoneCommand = new DelegateCommand<object>(Done);
             DoneCommand = new DelegateCommand<object>(Done);
             ItemChangeCommand = new DelegateCommand(ItemChange);
             ItemChangeCommand = new DelegateCommand(ItemChange);
+            UnLoadCommand = new DelegateCommand(Unload);
             BeforeConList = new ObservableCollection<BasPlcItemConfigDto>();
             BeforeConList = new ObservableCollection<BasPlcItemConfigDto>();
             InConList = new ObservableCollection<BasPlcItemConfigDto>();
             InConList = new ObservableCollection<BasPlcItemConfigDto>();
             OutConList = new ObservableCollection<BasPlcItemConfigDto>();
             OutConList = new ObservableCollection<BasPlcItemConfigDto>();
             GetConfigOption();
             GetConfigOption();
+            ReadPreTask();//读取前置项线程
+            m2.Set();
 
 
         }
         }
-        /// <summary>
-        /// 选中测试项
-        /// </summary>
-        private void ItemChange()
-        {
-            var findDtlMsg = _basicPlcTestSchemeDtlService.FindAllBySchId(schId)?.FirstOrDefault(X => X.item_name == SelectItem);
-            if (findDtlMsg != null)
-            {
-                int id = Convert.ToInt32(findDtlMsg.scheme_dtl_id);
-                // 根据 测试方案明细主键ID 查找测试方案id 及方案名和设备名
-                globalSchDetailId = id;
-                GetDetailInfo(id);
-            }
-        }
+
+     
 
 
 
 
 
 
@@ -278,6 +270,78 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         #endregion
         #endregion
 
 
         #region 私有发方法
         #region 私有发方法
+ 
+        CancellationTokenSource tokensource = new CancellationTokenSource(); //声明令牌
+        ManualResetEvent m2 = new ManualResetEvent(true); //实例化阻塞事件
+        private void ReadPreTask()
+        {
+            CancellationToken cancellationToken = tokensource.Token;
+            Task.Run(async () =>
+            {
+                while (true)
+                {
+                    if (cancellationToken.IsCancellationRequested)
+                    {
+                        return;
+                    }
+                    m2.WaitOne(); //当m等于true,才会往下执行,否则一直在此等待
+                    System.Windows.Application.Current.Dispatcher.Invoke((delegate
+                    {
+                        foreach (var item in BeforeConList.OrderBy(x => x.Id))
+                        {
+                            string plcAddress = item.PlcAddress;
+                            string plcAddType = item.PlcAddType;
+                            string plcValue = item.PlcValue;
+
+                            switch (plcAddType)
+                            {
+                                case "bool":
+                                    string readResult = PLCConnectionFactory.CreatePLCCont().ReadPlcObject(plcAddress, VarType.Bit);
+                                    ///实时值记录
+
+                                    item.RealValue = readResult;
+                                    item.TestTime = DateTime.Now;
+
+                                    break;
+                                case "word":
+                                    string readResult2 = PLCConnectionFactory.CreatePLCCont().ReadPlcObject(plcAddress, VarType.Word);
+                                    ///实时值记录
+
+                                    item.RealValue = readResult2;
+                                    item.TestTime = DateTime.Now;
+
+                                    break;
+
+                            }
+
+                        }
+                    }));
+
+                    await Task.Delay(2000);
+                }
+
+            }, cancellationToken);//绑定令牌到多线程;
+        }
+
+        private void Unload()
+        {
+            tokensource.Cancel(); //取消读取前置项的线程
+        }
+        /// <summary>
+        /// 选中测试项
+        /// </summary>
+        private void ItemChange()
+        {
+            m2.Set();  //继续线程(读取前置项)
+            var findDtlMsg = _basicPlcTestSchemeDtlService.FindAllBySchId(schId)?.FirstOrDefault(X => X.item_name == SelectItem);
+            if (findDtlMsg != null)
+            {
+                int id = Convert.ToInt32(findDtlMsg.scheme_dtl_id);
+                // 根据 测试方案明细主键ID 查找测试方案id 及方案名和设备名
+                globalSchDetailId = id;
+                GetDetailInfo(id);
+            }
+        }
         /// <summary>
         /// <summary>
         /// 增加或更新测试记录
         /// 增加或更新测试记录
         /// </summary>
         /// </summary>
@@ -581,6 +645,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
 
 
         private void Next(object obj)
         private void Next(object obj)
         {
         {
+            m2.Set();  //继续线程(读取前置项)
             StepIndex = 0;
             StepIndex = 0;
             ///查找方案下的所有方案明细,并排序,
             ///查找方案下的所有方案明细,并排序,
             var basicSchDtls = _basicPlcTestSchemeDtlService.FindAllBySchId(schId)?.OrderBy(x => x.sort).ThenBy(x => x.scheme_dtl_id);
             var basicSchDtls = _basicPlcTestSchemeDtlService.FindAllBySchId(schId)?.OrderBy(x => x.sort).ThenBy(x => x.scheme_dtl_id);
@@ -611,6 +676,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
 
 
         private void Previous(object obj)
         private void Previous(object obj)
         {
         {
+            m2.Set();  //继续线程(读取前置项)
             StepIndex = 0;
             StepIndex = 0;
             ///查找方案下的所有方案明细,并排序,
             ///查找方案下的所有方案明细,并排序,
             var basicSchDtls = _basicPlcTestSchemeDtlService.FindAllBySchId(schId)?.OrderByDescending(x => x.sort).ThenByDescending(x=>x.scheme_dtl_id);
             var basicSchDtls = _basicPlcTestSchemeDtlService.FindAllBySchId(schId)?.OrderByDescending(x => x.sort).ThenByDescending(x=>x.scheme_dtl_id);
@@ -646,7 +712,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         private async void Start(object obj)
         private async void Start(object obj)
         {
         {
 
 
-
+            m2.Reset();  //阻塞线程(不再读取前置项)
             StartEnalbe = false;
             StartEnalbe = false;
             _logger.LogInformation($"开始手动测试。方案名{ScheduleName},测试项{TestName}");
             _logger.LogInformation($"开始手动测试。方案名{ScheduleName},测试项{TestName}");
             SendLogToDis($"开始手动测试。方案名{ScheduleName},测试项{TestName}");
             SendLogToDis($"开始手动测试。方案名{ScheduleName},测试项{TestName}");
@@ -678,6 +744,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
             {
             {
                 MessageBoxResult boxResult = MessageBox.Show("前置项条件不满足,请确认前置条件!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
                 MessageBoxResult boxResult = MessageBox.Show("前置项条件不满足,请确认前置条件!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
                 StartEnalbe = true;
                 StartEnalbe = true;
+                m2.Set();  //继续线程(读取前置项)
                 return;
                 return;
             }
             }
             //输出项
             //输出项
@@ -799,6 +866,20 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                         }
                         }
                         break;
                         break;
                     case "word":
                     case "word":
+                        string readResult2 = PLCConnectionFactory.CreatePLCCont().ReadPlcObject(plcAddress, VarType.Word);
+                        ///实时值记录
+
+                        item.RealValue = readResult2;
+                        item.TestTime = DateTime.Now;
+                        if (readResult2.Trim() == plcValue?.Trim())
+                        {
+                            item.TestResult = "通过";
+                            countCond++;
+                        }
+                        else
+                        {
+                            item.TestResult = "不通过";
+                        }
                         break;
                         break;
 
 
                 }
                 }
@@ -1317,7 +1398,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
 
 
         public DelegateCommand<object> DoneCommand { set; get; }
         public DelegateCommand<object> DoneCommand { set; get; }
         public DelegateCommand ItemChangeCommand { set; get; }
         public DelegateCommand ItemChangeCommand { set; get; }
-
+        public DelegateCommand UnLoadCommand { set; get; }
         #endregion
         #endregion
         #region 变量绑定
         #region 变量绑定
         /// <summary>
         /// <summary>

+ 5 - 0
BlankApp1/BlankApp1/Views/BusinessManageView/ManualTestView.xaml

@@ -36,6 +36,11 @@
     </UserControl.Resources>
     </UserControl.Resources>
 
 
     <Grid>
     <Grid>
+        <b:Interaction.Triggers>
+            <b:EventTrigger EventName="Unloaded">
+                <b:InvokeCommandAction Command="{Binding UnLoadCommand}"/>
+            </b:EventTrigger>
+        </b:Interaction.Triggers>
         <Grid.ColumnDefinitions>
         <Grid.ColumnDefinitions>
             <ColumnDefinition Width="auto"/>
             <ColumnDefinition Width="auto"/>
             <ColumnDefinition/>
             <ColumnDefinition/>

+ 5 - 0
BlankApp1/BlankApp1/Views/BusinessManageView/RetryTestView.xaml

@@ -36,6 +36,11 @@
     </UserControl.Resources>
     </UserControl.Resources>
 
 
     <Grid>
     <Grid>
+        <b:Interaction.Triggers>
+            <b:EventTrigger EventName="Unloaded">
+                <b:InvokeCommandAction Command="{Binding UnLoadCommand}"/>
+            </b:EventTrigger>
+        </b:Interaction.Triggers>
         <Grid.ColumnDefinitions>
         <Grid.ColumnDefinitions>
             <ColumnDefinition Width="auto"/>
             <ColumnDefinition Width="auto"/>
             <ColumnDefinition/>
             <ColumnDefinition/>