/// <summary> /// Callback for when focused component changes, if <see cref="Component"/> was part of the action invokes PropertyChanged event /// for <see cref="IsFocused"/> /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FocusedComponentChanged(object sender, FocusedComponentChangedEventArgs e) { if (e.GotFocus == Component || e.LostFocus == Component) { InvokePropertyChanged(nameof(IsFocused)); } }
/// <summary> /// Callback for when focused component changes; removes, updates or creates a new <see cref="_Value"/> /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FocusedComponentChanged(object sender, FocusedComponentChangedEventArgs e) { // If the focus did not change (shouldn't happen but it's better to cover this case) if (e.LostFocus == e.GotFocus) { // Don't do anything return; } // Unsubscribe from the component that lost focus if (e.LostFocus != null) { e.LostFocus.PropertyChanged -= FocusedComponentPropertyChangedCallback; } // Subscribe to the newly focused component if (e.GotFocus != null) { e.GotFocus.PropertyChanged += FocusedComponentPropertyChangedCallback; } // If both the old and new component aren't null, they have the same type and _Info is already constructed if (e.LostFocus != null && e.GotFocus != null && e.LostFocus.GetType() == e.GotFocus.GetType() && _Value != null) { // Update it _Value.Update(e.GotFocus); // And return it return; } // If we got here it means that the _Info will either be removed, changed or constructed so, no matter which case it is, // reset _Info _Value = null; // If an element gets focus and it requests info display if (e.GotFocus != null && _DisplaySettings.TryGetValue(e.GotFocus.GetType(), out var infoSections)) { // Construct a ComponentInfo for it _Value = new ComponentInfo(infoSections, e.GotFocus); } }