diff --git a/src/Resources/Styles/Window.xaml b/src/Resources/Styles/Window.xaml
index 146b2dea..6d48ec29 100644
--- a/src/Resources/Styles/Window.xaml
+++ b/src/Resources/Styles/Window.xaml
@@ -19,10 +19,20 @@
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Views/Controls/DragDropAdorner.cs b/src/Views/Controls/DragDropAdorner.cs
index 2adb2d16..31126fb2 100644
--- a/src/Views/Controls/DragDropAdorner.cs
+++ b/src/Views/Controls/DragDropAdorner.cs
@@ -1,39 +1,9 @@
using System.Runtime.InteropServices;
using System.Windows;
-using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
namespace SourceGit.Views.Controls {
-
- ///
- /// DragDropAdorner容器
- ///
- public class DragDropAdornerLayer : Grid {
- private static AdornerLayer host = null;
- private static bool enableFeedback = false;
-
- public DragDropAdornerLayer() {
- Loaded += (o, e) => host = AdornerLayer.GetAdornerLayer(this);
- PreviewGiveFeedback += OnPreviewGiveFeedback;
- }
-
- public static void Add(Adorner adorner) {
- host.Add(adorner);
- enableFeedback = true;
- }
-
- public static void Remove(Adorner adorner) {
- host.Remove(adorner);
- enableFeedback = false;
- }
-
- private static void OnPreviewGiveFeedback(object sender, GiveFeedbackEventArgs e) {
- if (enableFeedback) host.Update();
- e.Handled = true;
- }
- }
-
///
/// 展示正在拖拽的视图
///
@@ -56,11 +26,11 @@ namespace SourceGit.Views.Controls {
renderSize = elem.RenderSize;
renderBrush = new VisualBrush(elem);
IsHitTestVisible = false;
- DragDropAdornerLayer.Add(this);
+ Window.AddAdorner(elem, this);
}
public void Remove() {
- DragDropAdornerLayer.Remove(this);
+ Window.RemoveAdorner(this);
}
protected override void OnRender(DrawingContext dc) {
@@ -73,6 +43,7 @@ namespace SourceGit.Views.Controls {
Rect rect = new Rect(pos.X, pos.Y, renderSize.Width, renderSize.Height);
dc.PushOpacity(1);
+ dc.DrawRectangle(FindResource("Brush.Window") as Brush, null, rect);
dc.DrawRectangle(renderBrush, null, rect);
dc.DrawRectangle(null, new Pen(Brushes.DeepSkyBlue, 2), rect);
}
diff --git a/src/Views/Controls/Window.cs b/src/Views/Controls/Window.cs
index d161a4db..07aaf767 100644
--- a/src/Views/Controls/Window.cs
+++ b/src/Views/Controls/Window.cs
@@ -1,4 +1,7 @@
+using System;
using System.Windows;
+using System.Windows.Documents;
+using System.Collections.Generic;
namespace SourceGit.Views.Controls {
///
@@ -17,20 +20,47 @@ namespace SourceGit.Views.Controls {
set { SetValue(IsMaximizedProperty, value); }
}
+ private AdornerLayer adornerLayer = null;
+ private List adorners = new List();
+
public Window() {
Style = FindResource("Style.Window") as Style;
+ Loaded += (_, __) => adornerLayer = AdornerLayer.GetAdornerLayer(Content as FrameworkElement);
+ }
- StateChanged += (_, __) => {
- var content = Content as FrameworkElement;
+ public static void AddAdorner(FrameworkElement elem, Adorner adorner) {
+ var wnd = GetWindow(elem) as Window;
+ if (wnd != null && wnd.adornerLayer != null) {
+ wnd.adorners.Add(adorner);
+ wnd.adornerLayer.Add(adorner);
+ }
+ }
- if (WindowState == WindowState.Maximized) {
- if (!IsMaximized) IsMaximized = true;
- content.Margin = new Thickness((SystemParameters.MaximizedPrimaryScreenWidth - SystemParameters.WorkArea.Width) / 2);
- } else {
- if (IsMaximized) IsMaximized = false;
- content.Margin = new Thickness(0);
- }
- };
+ public static void RemoveAdorner(Adorner adorner) {
+ var wnd = GetWindow(adorner) as Window;
+ if (wnd != null && wnd.adornerLayer != null) {
+ wnd.adorners.Remove(adorner);
+ wnd.adornerLayer.Remove(adorner);
+ }
+ }
+
+ protected override void OnPreviewGiveFeedback(GiveFeedbackEventArgs e) {
+ base.OnPreviewGiveFeedback(e);
+ if (adornerLayer != null && adorners.Count > 0) adornerLayer.Update();
+ }
+
+ protected override void OnStateChanged(EventArgs e) {
+ base.OnStateChanged(e);
+
+ if (WindowState == WindowState.Maximized) {
+ if (!IsMaximized) IsMaximized = true;
+ BorderThickness = new Thickness(0);
+ Padding = new Thickness((SystemParameters.MaximizedPrimaryScreenWidth - SystemParameters.WorkArea.Width) / 2);
+ } else {
+ if (IsMaximized) IsMaximized = false;
+ BorderThickness = new Thickness(1);
+ Padding = new Thickness(0);
+ }
}
private static void OnIsMaximizedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
diff --git a/src/Views/Launcher.xaml b/src/Views/Launcher.xaml
index 3e067076..c29c2f84 100644
--- a/src/Views/Launcher.xaml
+++ b/src/Views/Launcher.xaml
@@ -15,7 +15,7 @@
Width="{Binding Source={x:Static models:Preference.Instance}, Path=Window.Width, Mode=TwoWay}"
Height="{Binding Source={x:Static models:Preference.Instance}, Path=Window.Height, Mode=TwoWay}"
Closing="OnClosing">
-
+
@@ -61,5 +61,5 @@
Grid.Row="1"
HorizontalAlignment="Right" VerticalAlignment="Top"
Width="330" Height="Auto"/>
-
+