private void MoveDownButton_Click(object sender, RoutedEventArgs e) { var selected = (lstAvailableActions.SelectedItem as ActionInfo); var actionInfoGroup = ActionInfos.Where(ai => ai.GestureName.Equals(selected.GestureName, StringComparison.Ordinal)).ToList(); int index = actionInfoGroup.IndexOf(selected); if (index + 1 < actionInfoGroup.Count) { ActionInfos.Move(ActionInfos.IndexOf(selected), ActionInfos.IndexOf(actionInfoGroup[index + 1])); RefreshGroup(selected.GestureName); lstAvailableActions.SelectedItem = selected; IApplication selectedApplication = lstAvailableApplication.SelectedItem as IApplication; if (selectedApplication == null) { return; } int selectedIndex = selectedApplication.Actions.FindIndex(a => a.Name.Equals(selected.ActionName, StringComparison.Ordinal)); int nextIndex = selectedApplication.Actions.FindIndex(selectedIndex + 1, a => a.GestureName.Equals(selected.GestureName, StringComparison.Ordinal)); var temp = selectedApplication.Actions[nextIndex]; selectedApplication.Actions[nextIndex] = selectedApplication.Actions[selectedIndex]; selectedApplication.Actions[selectedIndex] = temp; ApplicationManager.Instance.SaveApplications(); } }
// public static event EventHandler StartCapture; public AvailableActions() { InitializeComponent(); var actionsSourceView = new ListCollectionView(ActionInfos); //创建数据源的视图 actionsSourceView.GroupDescriptions.Add(new PropertyGroupDescription("GestureName")); //在图中添加分组 actionsSourceView.SortDescriptions.Add(new SortDescription("GestureName", ListSortDirection.Ascending)); lstAvailableActions.ItemsSource = actionsSourceView; //绑定数据源 var applicationSourceView = new ListCollectionView(_applications); var applicationGroupDesctrption = new PropertyGroupDescription("Group"); //设置分组列 applicationSourceView.GroupDescriptions.Add(applicationGroupDesctrption); //在图中添加分组 lstAvailableApplication.ItemsSource = applicationSourceView; ActionDialog.ActionsChanged += (o, e) => { if (lstAvailableApplication.SelectedItem == e.Application) { var oldActionInfo = ActionInfos.FirstOrDefault(ai => ai.ActionName.Equals(e.Action.Name, StringComparison.Ordinal)); if (oldActionInfo != null) { int index = ActionInfos.IndexOf(oldActionInfo); var newActionInfo = Action2ActionInfo(e.Action); ActionInfos[index] = newActionInfo; RefreshGroup(e.Action.GestureName); SelectAction(newActionInfo); } else { RefreshActions(false); } } else { BindApplications(); _selecteNewestItem = true; lstAvailableApplication.SelectedItem = e.Application; lstAvailableApplication.ScrollIntoView(e.Application); } }; AvailableGestures.GestureChanged += (o, e) => { RefreshActions(true); }; GestureDefinition.GesturesChanged += (o, e) => { RefreshActions(true); }; ApplicationDialog.UserApplicationChanged += (o, e) => { BindApplications(); lstAvailableApplication.SelectedItem = e.Application; lstAvailableApplication.ScrollIntoView(e.Application); }; ApplicationManager.OnLoadApplicationsCompleted += (o, e) => { this.Dispatcher.InvokeAsync(BindApplications); }; if (ApplicationManager.FinishedLoading) { BindApplications(); } }
void RefreshGroup(string gestureName) { lstAvailableActions.SelectedItem = null; var temp = ActionInfos.Where(ai => ai.GestureName.Equals(gestureName, StringComparison.Ordinal)).ToList(); foreach (ActionInfo ai in temp) { int i = ActionInfos.IndexOf(ai); ActionInfos.Remove(ai); ActionInfos.Insert(i, ai); } }
private void RefreshActions(bool refreshAll) { var selectedApplication = lstAvailableApplication.SelectedItem as IApplication; if (selectedApplication == null) { return; } if (refreshAll) { Action <object> refreshAction = (o) => { Dispatcher.Invoke(() => { ActionInfos.Clear(); }, DispatcherPriority.Loaded); AddActionsToGroup(selectedApplication.Actions); }; if (_addActionTask == null) { _addActionTask = Task.Factory.StartNew(refreshAction, null); } else { _addActionTask = _addActionTask.ContinueWith(refreshAction); } } else { _selecteNewestItem = true; var newApp = selectedApplication.Actions.Where(a => !ActionInfos.Any(ai => ai.Equals(a))).ToList(); var deletedApp = ActionInfos.Where(ai => !selectedApplication.Actions.Any(ai.Equals)).ToList(); if (newApp.Count == 1 && deletedApp.Count == 1) { var newActionInfo = Action2ActionInfo(newApp[0]); ActionInfos[ActionInfos.IndexOf(deletedApp[0])] = newActionInfo; RefreshGroup(newApp[0].GestureName); SelectAction(newActionInfo); } else { foreach (ActionInfo ai in deletedApp) { ActionInfos.Remove(ai); } AddActionsToGroup(newApp); } } }
private void UserControl_Initialized(object sender, EventArgs eArgs) { ActionDialog.ActionsChanged += (o, e) => { if (lstAvailableApplication.SelectedItem == e.Application) { var oldActionInfo = ActionInfos.FirstOrDefault(ai => ai.ActionName.Equals(e.Action.Name, StringComparison.Ordinal)); if (oldActionInfo != null) { int index = ActionInfos.IndexOf(oldActionInfo); var newActionInfo = Action2ActionInfo(e.Action); ActionInfos[index] = newActionInfo; RefreshGroup(e.Action.GestureName); SelectAction(newActionInfo); } else { RefreshActions(false); } } else { BindApplications(); _selecteNewestItem = true; lstAvailableApplication.SelectedItem = e.Application; lstAvailableApplication.ScrollIntoView(e.Application); } }; AvailableGestures.GestureChanged += (o, e) => { RefreshActions(true); }; GestureDefinition.GesturesChanged += (o, e) => { RefreshActions(true); }; ApplicationDialog.UserApplicationChanged += (o, e) => { BindApplications(); lstAvailableApplication.SelectedItem = e.Application; lstAvailableApplication.ScrollIntoView(e.Application); }; ApplicationManager.OnLoadApplicationsCompleted += (o, e) => { this.Dispatcher.InvokeAsync(BindApplications); }; if (ApplicationManager.FinishedLoading) { BindApplications(); } }