public void SetCommandBar(CommandBar commandBar) { if (_commandBarVisibilityToken > 0) { _commandBar.UnregisterPropertyChangedCallback(CommandBar.VisibilityProperty, _commandBarVisibilityToken); _commandBarVisibilityToken = -1; } _commandBar = commandBar; if (_isInitialized) { if (_commandBar != null) { _commandBarVisibilityToken = _commandBar.RegisterPropertyChangedCallback(CommandBar.VisibilityProperty, OnCommandBarVisibilityChanged); } _commandBarContainer.Content = _commandBar; SetCommandBarVerticalAlignment(this.CommandBarVerticalAlignment); } }