-
Notifications
You must be signed in to change notification settings - Fork 647
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clickable Interactive control sample for custom titlebar (#1360)
With 1.4 changes, WinUI 3 custom titlebar now uses appwindow titlebar + nonclientinputpointersource apis under the hood. This opens up new possibilities like allowing clickable interactive controls like textbox, button in the titlebar area, surrounded by draggable region on both left and the right sides. This code adds a sample to titlebar page which shows users how to create interactive controls in winui 3 titlebar. It also demonstrates the power of mixing and matching high level winui 3 custom titlebar apis and low level nonclient apis.
- Loading branch information
Showing
9 changed files
with
176 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
WinUIGallery/ControlPagesSampleCode/Window/TitleBar/TitleBarSample2.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// no UIElement is set for titlebar, fallback titlebar is created | ||
// no UIElement is set for titlebar, default titlebar is created which extends to entire non client area | ||
Window window = App.MainWindow; | ||
window.ExtendsContentIntoTitleBar = true; | ||
window.SetTitleBar(null); // this line is optional as by it is null by default | ||
// window.SetTitleBar(null); // optional line as not setting any UIElement as titlebar is same as setting null as titlebar |
22 changes: 22 additions & 0 deletions
22
WinUIGallery/ControlPagesSampleCode/Window/TitleBar/TitleBarSample3.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Window window = App.MainWindow; | ||
window.ExtendsContentIntoTitleBar = true; | ||
window.SetTitleBar(AppTitleBar); | ||
var nonClientInputSrc = InputNonClientPointerSource.GetForWindowId(window.AppWindow.Id); | ||
|
||
// textbox on titlebar area | ||
var txtBoxNonClientArea = UIHelper.FindElementByName(sender as UIElement, "AppTitleBarTextBox") as FrameworkElement; | ||
GeneralTransform transformTxtBox = txtBoxNonClientArea.TransformToVisual(null); | ||
Rect bounds = transformTxtBox.TransformBounds(new Rect(0, 0, txtBoxNonClientArea.ActualWidth, txtBoxNonClientArea.ActualHeight)); | ||
|
||
// Windows.Graphics.RectInt32[] rects defines the area which allows click throughs in custom titlebar | ||
// it is non dpi-aware client coordinates. Hence, we convert dpi aware coordinates to non-dpi coordinates | ||
var scale = WindowHelper.GetRasterizationScaleForElement(this); | ||
var transparentRect = new Windows.Graphics.RectInt32( | ||
_X: (int)Math.Round(bounds.X * scale), | ||
_Y: (int)Math.Round(bounds.Y * scale), | ||
_Width: (int)Math.Round(bounds.Width * scale), | ||
_Height: (int)Math.Round(bounds.Height * scale) | ||
); | ||
var rects = new Windows.Graphics.RectInt32[] { transparentRect }; | ||
|
||
nonClientInputSrc.SetRegionRects(NonClientRegionKind.Passthrough, rects); // areas defined will be click through and can host button and textboxes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters