一,场景

    通过单击按钮执行ViewModel中的Command来关闭窗体,项目引用Prism4架构及使用MVVM进行UI层的开发。

二, 实现代码(方式应该有很多种,现介绍两种我所想过的方式)

     (1).通过发布订阅事件来关闭窗体

     1.CodeBahind中的代码

 1   public partial class ApproveLoginView : Window
 2 
 3     {        
 4 
 5           [ImportingConstructor]         
 6 
 7           public ApproveLoginView()      
 8 
 9          {          
10 
11                   InitializeComponent();           
12 
13                   ServicesHelper.EventAggregator.GetEvent<CloseEvent>   ().Subscribe(CloseView);     
14 
15          }
16 
17         private void CloseView(object o)       
18 
19         {          
20 
21              if(o == DataContext)        
22 
23                     Close();           
24 
25         }     
26 
27 }
View Code

相关文章:

  • 2021-08-02
  • 2022-12-23
  • 2021-11-03
  • 2022-03-04
  • 2021-12-06
  • 2022-12-23
猜你喜欢
  • 2022-03-08
  • 2021-11-12
  • 2022-12-23
  • 2022-12-23
  • 2021-12-05
  • 2021-12-12
  • 2021-06-30
相关资源
相似解决方案