简体   繁体   中英

Windows Universal App SetTitleBar

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

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 the fuction(EnableControlsInTitleBar),the sample still work well

In Justin XL sample( https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/TitleBar ) there indeed have use this:

Window.Current.SetTitleBar(BackgroundElement);

that puzzled me,hope somebody can give me a explain,thanks.

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

I don't think it's the truth. There are several places will call this function, so I think you didn't comment out all of them.

The following line is used to let your custom title bar can handle input(for example the mouse click) like default title bar.

Window.Current.SetTitleBar(BackgroundElement);

Take the MS sample as example here. If we launch the MS sample without any change, you can do the following actions:

Select " 2) Custom drawing " -> check "Extend view into title bar" -> check "Enable controls in title bar" -> you will see the following title bar and be able to check the checkbox on title bar. 在此处输入图片说明

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM