"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 
But if we comment on the call to SetTitleBar, the checkbox will not respond to your mouse click.
source share