protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) { if (e.Property == IsVisibleProperty) { GameControlService.HookCommands(this, Command, Command); } base.OnPropertyChanged(e); }
public int IndexOf(string label) { for (var index = 0; index < Count; index++) { if (GameControlService.GetLabel(this[index]) == label) { return(index); } } return(-1); }
private UIElement GetTargetElement() { UIElement element = null; if (GameControlService.GetIsExternalContentSupported(this)) { element = this; } else if (VisualTreeHelper.GetChildrenCount(this) > 0) { // Look for a UIElement that is the child of the ContentPresenter (this will normally be a Button) var presenter = VisualTreeHelper.GetChild(this, 0) as ContentPresenter; if (presenter != null && VisualTreeHelper.GetChildrenCount(presenter) > 0) { element = VisualTreeHelper.GetChild(presenter, 0) as UIElement; } } return(element ?? this); }
void IGameControl.OnCommandUIProviderPropertyChanged(object sender, PropertyChangedEventArgs e) { GameControlService.UpdateUIFromCommand(this); }
protected override void OnContentChanged(object oldContent, object newContent) { base.OnContentChanged(oldContent, newContent); if (oldContent is DependencyObject) { BindingOperations.ClearBinding(this, PopupControlService.IsPopupOpenProperty); BindingOperations.ClearBinding(this, IsContentEnabledProperty); BindingOperations.ClearBinding(this, VisibilityProperty); // If the menu item's external content properties were bound, clear the bindings if (GameControlService.GetIsExternalContentSupported(this)) { BindingOperations.ClearBinding(this, GameControlService.ImageSourceLargeProperty); BindingOperations.ClearBinding(this, GameControlService.ImageSourceSmallProperty); BindingOperations.ClearBinding(this, GameControlService.LabelProperty); } } var newContentObj = newContent as DependencyObject; if (newContentObj != null) { // Update the IsTabStop property based on whether the child item keeps highlighted when focused IsTabStop = !CanUnhighlightWhenFocused(newContentObj); // Bind to IsPopupOpen var binding = new Binding { Mode = BindingMode.TwoWay, Source = newContent, Path = new PropertyPath(PopupControlService.IsPopupOpenProperty) }; SetBinding(PopupControlService.IsPopupOpenProperty, binding); if (newContent is UIElement) { // Bind to IsEnabled binding = new Binding { Source = newContent, Path = new PropertyPath("IsEnabled") }; SetBinding(IsContentEnabledProperty, binding); // Bind to Visibility binding = new Binding { Source = newContent, Path = new PropertyPath("Visibility") }; SetBinding(VisibilityProperty, binding); } // Tell the menu item whether external content is supported based on the content's settings var isExternalContentSupported = GameControlService.GetIsExternalContentSupported(newContentObj); GameControlService.SetIsExternalContentSupported(this, isExternalContentSupported); if (isExternalContentSupported) { // Configure bindings binding = new Binding { Source = newContent, Path = new PropertyPath(GameControlService.ImageSourceLargeProperty) }; SetBinding(GameControlService.ImageSourceLargeProperty, binding); binding = new Binding { Source = newContent, Path = new PropertyPath(GameControlService.ImageSourceSmallProperty) }; SetBinding(GameControlService.ImageSourceSmallProperty, binding); binding = new Binding { Source = newContent, Path = new PropertyPath(GameControlService.LabelProperty) }; SetBinding(GameControlService.LabelProperty, binding); } } else { GameControlService.SetIsExternalContentSupported(this, false); } }