|
1 | 1 | using System; |
| 2 | +using System.Reflection; |
2 | 3 | using System.Windows; |
3 | 4 | using System.Windows.Interop; |
4 | 5 | using System.Windows.Shell; |
5 | 6 | using Wpf.Ui.Appearance; |
6 | 7 | using Wpf.Ui.Controls; |
7 | | -using Wpf.Ui.Interop; |
8 | 8 |
|
9 | 9 | namespace Wpf.Ui.Violeta.Controls; |
10 | 10 |
|
@@ -222,3 +222,47 @@ protected virtual void OnExtendsContentIntoTitleBarChanged(bool oldValue, bool n |
222 | 222 | _ = UnsafeNativeMethods.RemoveWindowTitlebarContents(this); |
223 | 223 | } |
224 | 224 | } |
| 225 | + |
| 226 | +/// <summary> |
| 227 | +/// Reflective access to `Wpf.Ui.Interop.UnsafeNativeMethods` methods. |
| 228 | +/// </summary> |
| 229 | +file static class UnsafeNativeMethods |
| 230 | +{ |
| 231 | + private static readonly Type? _interopType |
| 232 | + = Type.GetType("Wpf.Ui.Interop.UnsafeNativeMethods, Wpf.Ui"); |
| 233 | + |
| 234 | + /// <summary> |
| 235 | + /// Tries to set the corner preference of the selected window. |
| 236 | + /// </summary> |
| 237 | + /// <param name="handle">Selected window handle.</param> |
| 238 | + /// <param name="cornerPreference">Window corner preference.</param> |
| 239 | + /// <returns><see langword="true"/> if invocation of native Windows function succeeds.</returns> |
| 240 | + public static bool ApplyWindowCornerPreference(nint handle, object cornerPreference) |
| 241 | + { |
| 242 | + if (_interopType == null) return false; |
| 243 | + |
| 244 | + MethodInfo? method = _interopType.GetMethod("ApplyWindowCornerPreference", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); |
| 245 | + if (method == null) return false; |
| 246 | + return (bool)method.Invoke(null, [handle, cornerPreference])!; |
| 247 | + } |
| 248 | + |
| 249 | + /// <summary> |
| 250 | + /// Tries to remove titlebar from selected <see cref="Window"/>. |
| 251 | + /// </summary> |
| 252 | + /// <param name="window">The window to which the effect is to be applied.</param> |
| 253 | + /// <returns><see langword="true"/> if invocation of native Windows function succeeds.</returns> |
| 254 | + public static bool RemoveWindowTitlebarContents(Window? window) |
| 255 | + { |
| 256 | + if (_interopType == null) return false; |
| 257 | + |
| 258 | + MethodInfo? method = _interopType.GetMethod( |
| 259 | + "RemoveWindowTitlebarContents", |
| 260 | + BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, |
| 261 | + null, |
| 262 | + [typeof(Window)], |
| 263 | + null |
| 264 | + ); |
| 265 | + if (method == null) return false; |
| 266 | + return (bool)method.Invoke(null, [window])!; |
| 267 | + } |
| 268 | +} |
0 commit comments