Ramitta
我是米塔更新
This commit is contained in:
107
Ramitta/winTitleBar.xaml.cs
Normal file
107
Ramitta/winTitleBar.xaml.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Ramitta
|
||||
{
|
||||
public partial class winTitleBar : UserControl
|
||||
{
|
||||
public winTitleBar()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
#region 命令执行方法
|
||||
|
||||
private void MinimizeCommand_Executed(object sender, ExecutedRoutedEventArgs e)
|
||||
{
|
||||
var window = Window.GetWindow(this);
|
||||
if (window != null)
|
||||
{
|
||||
window.WindowState = WindowState.Minimized;
|
||||
}
|
||||
}
|
||||
|
||||
private void MaximizeCommand_Executed(object sender, ExecutedRoutedEventArgs e)
|
||||
{
|
||||
var window = Window.GetWindow(this);
|
||||
if (window != null)
|
||||
{
|
||||
window.WindowState = window.WindowState == WindowState.Maximized
|
||||
? WindowState.Normal
|
||||
: WindowState.Maximized;
|
||||
}
|
||||
}
|
||||
|
||||
private void CloseCommand_Executed(object sender, ExecutedRoutedEventArgs e)
|
||||
{
|
||||
var window = Window.GetWindow(this);
|
||||
if (window != null)
|
||||
{
|
||||
window.Close();
|
||||
}
|
||||
}
|
||||
|
||||
private void DragMoveCommand_Executed(object sender, ExecutedRoutedEventArgs e)
|
||||
{
|
||||
var window = Window.GetWindow(this);
|
||||
if (window != null)
|
||||
{
|
||||
window.DragMove();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 鼠标事件处理
|
||||
|
||||
private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (e.ChangedButton == MouseButton.Left && e.ClickCount == 2)
|
||||
{
|
||||
// 双击标题栏切换最大化/还原
|
||||
var window = Window.GetWindow(this);
|
||||
if (window != null)
|
||||
{
|
||||
window.WindowState = window.WindowState == WindowState.Maximized
|
||||
? WindowState.Normal
|
||||
: WindowState.Maximized;
|
||||
}
|
||||
}
|
||||
else if (e.ChangedButton == MouseButton.Left)
|
||||
{
|
||||
// 单机拖动窗口
|
||||
var window = Window.GetWindow(this);
|
||||
window?.DragMove();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 依赖属性
|
||||
|
||||
public static readonly DependencyProperty TitleProperty =
|
||||
DependencyProperty.Register("Title", typeof(string), typeof(winTitleBar),
|
||||
new PropertyMetadata("Application"));
|
||||
|
||||
public string Title
|
||||
{
|
||||
get { return (string)GetValue(TitleProperty); }
|
||||
set { SetValue(TitleProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IconProperty =
|
||||
DependencyProperty.Register("Icon", typeof(ImageSource), typeof(winTitleBar),
|
||||
new PropertyMetadata(null));
|
||||
|
||||
public ImageSource Icon
|
||||
{
|
||||
get { return (ImageSource)GetValue(IconProperty); }
|
||||
set { SetValue(IconProperty, value); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user