自定义窗体,简简单单实现
2020-12-13 03:06
标签:style class blog code http tar style文件xmal: 继承类cs: 要使用这个自定义窗体,继承即可: 自定义窗体,简简单单实现,搜素材,soscw.com 自定义窗体,简简单单实现 标签:style class blog code http tar 原文地址:http://www.cnblogs.com/Events/p/3794950.htmlResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace WisHotel.Common
{
public class BaseWindow : Window
{
public BaseWindow()
{
//居中显示
WindowStartupLocation = WindowStartupLocation.CenterScreen;
//初始化样式
this.Style = (Style)App.Current.Resources["BaseWindowStyle"];
//下面两句是做的这个基类是用来做类似弹出编辑的小窗体和MessageBox
this.ShowInTaskbar = false;//不在任务栏显示
this.Owner = Application.Current.MainWindow;//绑定主窗口
this.Loaded += delegate
{
InitializeEvent();
};
}
private void InitializeEvent()
{
ControlTemplate baseWindowTemplate = (ControlTemplate)App.Current.Resources["BaseWindowControlTemplate"];
TextBlock TitleTextBlock = (TextBlock)baseWindowTemplate.FindName("Title", this);
TitleTextBlock.Text = this.Title;
Button minBtn = (Button)baseWindowTemplate.FindName("btnMin", this);
minBtn.Click += delegate
{
this.WindowState = WindowState.Minimized;
};
Button maxBtn = (Button)baseWindowTemplate.FindName("btnMax", this);
maxBtn.Click += delegate
{
this.WindowState = (this.WindowState == WindowState.Normal ? WindowState.Maximized : WindowState.Normal);
};
Button closeBtn = (Button)baseWindowTemplate.FindName("btnClose", this);
closeBtn.Click += delegate
{
this.Close();
};
Border borderTitle = (Border)baseWindowTemplate.FindName("borderTitle", this);
borderTitle.MouseMove += delegate(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
this.DragMove();
}
};
borderTitle.MouseLeftButtonDown += delegate(object sender, MouseButtonEventArgs e)
{
if (e.ClickCount >= 2)
{
//maxBtn.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));//双击放大
}
};
}
}
}