zoukankan      html  css  js  c++  java
  • MVVM 模版里的控件怎样触发命令

     1 public class BaseWindow : Window
     2     {
     3         public BaseWindow()
     4         {
     5             InitializeStyle();

                      //给样式的控件加载事件
    6 this.Loaded += delegate 7 { 8 InitializeEvent(); 9 }; 10 } 11 12 private void InitializeEvent() 13 { 14 ControlTemplate baseWindowTemplate = (ControlTemplate)App.Current.Resources["BaseWindowControlTemplate"]; 15 16 Button minBtn = (Button)baseWindowTemplate.FindName("btnMin", this); 17 minBtn.Click += delegate 18 { 19 this.WindowState = WindowState.Minimized; 20 }; 21 22 Button maxBtn = (Button)baseWindowTemplate.FindName("btnMax", this); 23 maxBtn.Click += delegate 24 { 25 this.WindowState = (this.WindowState == WindowState.Normal ? WindowState.Maximized : WindowState.Normal); 26 }; 27 28 Button closeBtn = (Button)baseWindowTemplate.FindName("btnClose", this); 29 closeBtn.Click += delegate 30 { 31 this.Close(); 32 }; 33 34 Border borderTitle = (Border)baseWindowTemplate.FindName("borderTitle", this); 35 borderTitle.MouseMove += delegate(object sender, MouseEventArgs e) 36 { 37 if (e.LeftButton == MouseButtonState.Pressed) 38 { 39 this.DragMove(); 40 } 41 }; 42 borderTitle.MouseLeftButtonDown += delegate(object sender, MouseButtonEventArgs e) 43 { 44 if (e.ClickCount >= 2) 45 { 46 maxBtn.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); 47 } 48 }; 49 } 50 51 52 private void InitializeStyle() 53 { 54 this.Style = (Style) App.Current.Resources["BaseWindowStyle"]; 55 } 56 }
  • 相关阅读:
    C 实战练习题目20 – 小球自由下落
    C 实战练习题目19
    C 实战练习题目18
    C 实战练习题目17
    C 实战练习题目16 -最大公约数和最小公倍数
    C 实战练习题目15
    C 实战练习题目14 -将一个正整数分解质因数
    C 实战练习题目13 -水仙花数
    C 实战练习题目12
    C 实战练习题目11
  • 原文地址:https://www.cnblogs.com/qq247039968/p/4231767.html
Copyright © 2011-2022 走看看