Windows Universal App SetTitleBar

I have a question about the Title'Bar sample from the Microsoft GitHub repository ( https://github.com/JustinXinLiu/FullScreenTitleBarRepo/tree/master/FullScreenTitleBarRepo ): there is a line in the AddCustomTitleBar function:

customTitleBar.EnableControlsInTitleBar(areControlsInTitleBar); 

EnableControlsInTitleBar is here:

 public void EnableControlsInTitleBar(bool enable) { if (enable) { TitleBarControl.Visibility = Visibility.Visible; // Clicks on the BackgroundElement will be treated as clicks on the title bar. Window.Current.SetTitleBar(BackgroundElement); } else { TitleBarControl.Visibility = Visibility.Collapsed; Window.Current.SetTitleBar(null); } } 

but if i don't call fuction (EnableControlsInTitleBar) the sample still works fine

The Justin XL example ( https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/TitleBar ) really uses the following:

 Window.Current.SetTitleBar(BackgroundElement); 

that puzzled me, I hope someone can give me an explanation, thanks.

+1
source share
1 answer

"but if I don't call fuction (EnableControlsInTitleBar), the sample still works well."

I do not think this is true. There are several places that will call this function, so I think you have not commented on all of them.

The next line is used so that your custom header line can handle input (for example, a mouse click), like the default title bar.

 Window.Current.SetTitleBar(BackgroundElement); 

Take an MS sample as an example here. If we run the MS sample without any changes, you can do the following:

Select โ€œ 2) Custom Drawing โ€ โ†’ check the box โ€œExtend the view in the title barโ€ โ†’ check the box โ€œEnable controls in the title barโ€ โ†’ you will see the next title bar and you can check the box in the title bar enter image description here

But if we comment on the call to SetTitleBar, the checkbox will not respond to your mouse click.

+1
source

All Articles