public HorizontalModLayout() { InitializeComponent(); SetupListView(ActiveModsListView); SetupListView(InactiveModsListView); ActiveModsListView.SelectionChanged += (object sender, SelectionChangedEventArgs e) => { if (ActiveModsListView.Items.Count == 0) { return; } UpdateIsSelected(e, ViewModel.ActiveMods); }; InactiveModsListView.SelectionChanged += (object sender, SelectionChangedEventArgs e) => { if (InactiveModsListView.Items.Count == 0) { return; } UpdateIsSelected(e, ViewModel.InactiveMods); }; ActiveModsListView.ItemContainerGenerator.StatusChanged += ActiveModListView_ItemContainerStatusChanged; InactiveModsListView.ItemContainerGenerator.StatusChanged += InactiveModListView_ItemContainerStatusChanged; this.KeyDown += HorizontalModLayout_KeyDown; this.KeyUp += HorizontalModLayout_KeyUp; this.LostFocus += (o, e) => { canMoveSelectedMods = true; }; bool setInitialFocus = true; this.Loaded += (o, e) => { if (setInitialFocus) { this.ActiveModsListView.Focus(); if (ViewModel.ActiveSelected <= 0) { ActiveModsListView.SelectedIndex = 0; } try { ListViewItem item = (ListViewItem)ActiveModsListView.ItemContainerGenerator.ContainerFromItem(ActiveModsListView.SelectedItem); if (item != null) { Keyboard.Focus(item); } } catch (Exception ex) { DivinityApp.Log($"Error focusing selected item:{ex}"); } setInitialFocus = false; } }; DataContextChanged += (o, e) => { if (e.NewValue != null && e.NewValue is MainWindowViewModel vm) { ViewModel = vm; BindingOperations.SetBinding(ActiveModsListView, ListView.ItemsSourceProperty, new Binding { Path = new PropertyPath("ActiveMods"), Source = ViewModel }); BindingOperations.SetBinding(InactiveModsListView, ListView.ItemsSourceProperty, new Binding { Path = new PropertyPath("InactiveMods"), Source = ViewModel }); } }; this.WhenActivated((d) => { if (ViewModel != null) { ViewModel.OnOrderChanged += AutoSizeNameColumn_ActiveMods; ViewModel.OnOrderChanged += AutoSizeNameColumn_InactiveMods; ViewModel.Layout = this; //ViewModel.Keys.Confirm.AddAction(() => //{ // if(ListHasFocus(ActiveModsListView) || ListHasFocus(InactiveModsListView)) // { // //MoveSelectedMods(); // } //}); ViewModel.Keys.MoveFocusLeft.AddAction(() => { DivinityApp.IsKeyboardNavigating = true; this.ActiveModsListView.Focus(); if (ViewModel != null) { if (ViewModel.ActiveSelected <= 0) { ActiveModsListView.SelectedIndex = 0; } } //InactiveModsListView.UnselectAll(); FocusList(ActiveModsListView); }); ViewModel.Keys.MoveFocusRight.AddAction(() => { DivinityApp.IsKeyboardNavigating = true; InactiveModsListView.Focus(); if (ViewModel != null) { if (ViewModel.ActiveSelected <= 0) { InactiveModsListView.SelectedIndex = 0; } } //ActiveModsListView.UnselectAll(); FocusList(InactiveModsListView); }); ViewModel.Keys.SwapListFocus.AddAction(() => { if (ListHasFocus(InactiveModsListView)) { DivinityApp.IsKeyboardNavigating = true; FocusList(ActiveModsListView); } else if (ListHasFocus(ActiveModsListView)) { DivinityApp.IsKeyboardNavigating = true; FocusList(InactiveModsListView); } }); //InactiveModsListView.InputBindings.Add(new InputBinding(ViewModel.MoveLeftCommand, new KeyGesture(Key.Left))); ViewModel.Keys.ToggleFilterFocus.AddAction(() => { if (ListHasFocus(ActiveModsListView)) { if (!this.ActiveModsFilterTextBox.IsFocused) { this.ActiveModsFilterTextBox.Focus(); } else { FocusSelectedItem(ActiveModsListView); } } else { if (!this.InactiveModsFilterTextBox.IsFocused) { this.InactiveModsFilterTextBox.Focus(); } else { FocusSelectedItem(InactiveModsListView); } } }); //ActiveModsListView.InputBindings.Add(new InputBinding(ViewModel.MoveRightCommand, new KeyGesture(Key.Right))); ViewModel.WhenAnyValue(x => x.ActiveSelected).Subscribe((c) => { if (c > 1 && DivinityApp.IsScreenReaderActive()) { var peer = UIElementAutomationPeer.FromElement(this.ActiveSelectedText); if (peer == null) { peer = UIElementAutomationPeer.CreatePeerForElement(this.ActiveSelectedText); } peer.RaiseAutomationEvent(AutomationEvents.LiveRegionChanged); } }).DisposeWith(d); ViewModel.WhenAnyValue(x => x.InactiveSelected).Subscribe((c) => { if (c > 1 && DivinityApp.IsScreenReaderActive()) { var peer = UIElementAutomationPeer.FromElement(this.InactiveSelectedText); if (peer == null) { peer = UIElementAutomationPeer.CreatePeerForElement(this.InactiveSelectedText); } peer.RaiseAutomationEvent(AutomationEvents.LiveRegionChanged); } }).DisposeWith(d); } //BindingHelper.CreateCommandBinding(ViewModel.View.EditFocusActiveListMenuItem, "MoveLeftCommand", ViewModel); // when the ViewModel gets deactivated Disposable.Create(() => { if (ViewModel != null) { ViewModel.OnOrderChanged -= AutoSizeNameColumn_ActiveMods; ViewModel.OnOrderChanged -= AutoSizeNameColumn_InactiveMods; } }).DisposeWith(d); }); }