天天看点

从模版中找到控件的方法和找到样式的方法

原文:

从模版中找到控件的方法和找到样式的方法

this.Style = (Style) App.Current.Resources["BaseWindowStyle"];

运行下段代码一定要加载样式完成后

i最好是在 Loaded 事件运行完成后加载  

ControlTemplate baseWindowTemplate = (ControlTemplate)App.Current.Resources["BaseWindowControlTemplate"];

Button minBtn = (Button)baseWindowTemplate.FindName("btnMin", this);

minBtn.Click += delegate

{

this.WindowState = WindowState.Minimized;

};