|
1 | 1 | using System; |
2 | 2 | using System.Windows; |
3 | 3 | using System.Windows.Controls; |
| 4 | +using System.Windows.Data; |
4 | 5 | using System.Windows.Interop; |
5 | 6 | using System.Windows.Media; |
| 7 | +using System.Windows.Shell; |
6 | 8 | using HandyControl.Data; |
7 | 9 | using HandyControl.Tools; |
8 | 10 | using HandyControl.Tools.Interop; |
@@ -135,4 +137,46 @@ private void Window_SizeChanged(object sender, SizeChangedEventArgs e) |
135 | 137 | FixCut(); |
136 | 138 | } |
137 | 139 | } |
| 140 | + |
| 141 | + private void ApplyWindowChrome(WindowState windowsState) |
| 142 | + { |
| 143 | +#if NET40 |
| 144 | + var chrome = new WindowChrome |
| 145 | + { |
| 146 | + CornerRadius = new CornerRadius(), |
| 147 | + GlassFrameThickness = new Thickness(0, 0, 0, 1) |
| 148 | + }; |
| 149 | +#else |
| 150 | + var chrome = new WindowChrome() |
| 151 | + { |
| 152 | + CaptionHeight = NonClientAreaHeight - 7, |
| 153 | + CornerRadius = new CornerRadius(8), |
| 154 | + GlassFrameThickness = new Thickness(-1), |
| 155 | + ResizeBorderThickness = new Thickness(6) |
| 156 | + }; |
| 157 | + if (windowsState == WindowState.Maximized) |
| 158 | + { |
| 159 | + chrome.ResizeBorderThickness = new Thickness(0); |
| 160 | + } |
| 161 | + else |
| 162 | + { |
| 163 | + chrome.ResizeBorderThickness = new Thickness(6); |
| 164 | + } |
| 165 | +#endif |
| 166 | + BindingOperations.SetBinding(chrome, WindowChrome.CaptionHeightProperty, |
| 167 | + new Binding(NonClientAreaHeightProperty.Name) { Source = this }); |
| 168 | + WindowChrome.SetWindowChrome(this, chrome); |
| 169 | + } |
| 170 | + |
| 171 | +#if !NET40 |
| 172 | + protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) |
| 173 | + { |
| 174 | + if (e.Property.Name is nameof(WindowState)) |
| 175 | + { |
| 176 | + ApplyWindowChrome((WindowState) e.NewValue); |
| 177 | + } |
| 178 | + base.OnPropertyChanged(e); |
| 179 | + } |
| 180 | +#endif |
| 181 | + |
138 | 182 | } |
0 commit comments