/// <summary> /// 选中数据移动方法 /// </summary> protected async Task Transfer(List <SelectedItem> source, List <SelectedItem> target) { if (!IsDisabled) { var items = source.Where(i => i.Active).ToList(); source.RemoveAll(i => i.Active); items.ForEach(i => i.Active = false); target.AddRange(items); // 回调 if (ItemsChanged.HasDelegate && Items != null) { var s = Items.ToList(); LeftItems.ToList().ForEach(i => { var index = s.FindIndex(item => item.Value == i.Value && item.Text == i.Text && item.GroupName == i.GroupName); s[index].Active = false; }); RightItems.ToList().ForEach(i => { var index = s.FindIndex(item => item.Value == i.Value && item.Text == i.Text && item.GroupName == i.GroupName); s[index].Active = true; }); await ItemsChanged.InvokeAsync(s); } } }
/// <summary> /// 选中数据移动方法 /// </summary> private async Task TransferItems(List <SelectedItem> source, List <SelectedItem> target) { if (!IsDisabled && Items != null) { var items = source.Where(i => i.Active).ToList(); source.RemoveAll(i => items.Contains(i)); target.AddRange(items); LeftItems.ForEach(i => { var item = Items.FirstOrDefault(item => item.Value == i.Value && item.Text == i.Text && item.GroupName == i.GroupName); if (item != null) { item.Active = false; } }); RightItems.ForEach(i => { var item = Items.FirstOrDefault(item => item.Value == i.Value && item.Text == i.Text && item.GroupName == i.GroupName); if (item != null) { item.Active = true; } }); Value = default; CurrentValueAsString = string.Join(",", RightItems.Select(i => i.Value)); if (OnSelectedItemsChanged != null) { await OnSelectedItemsChanged.Invoke(RightItems); } } }
/// <summary> /// Fill Column list boxs. /// </summary> public void fill() { lstLeftColumn.Items.Clear(); lstRightColumn.Items.Clear(); // Fill left column if (mLeftItems != null) { for (int i = LeftItems.GetLowerBound(0); i <= LeftItems.GetUpperBound(0); i++) { ListItem li = new ListItem(LeftItems[i, 1], LeftItems[i, 0]); lstLeftColumn.Items.Add(li); } } // Fill right column if (mRightItems != null) { for (int i = RightItems.GetLowerBound(0); i <= RightItems.GetUpperBound(0); i++) { ListItem li = new ListItem(RightItems[i, 1], RightItems[i, 0]); lstRightColumn.Items.Add(li); } } }
/// <summary> /// OnParametersSet 方法 /// </summary> protected override void OnParametersSet() { base.OnParametersSet(); LeftPanelText ??= Localizer[nameof(LeftPanelText)]; RightPanelText ??= Localizer[nameof(RightPanelText)]; var list = CurrentValueAsString.Split(',', StringSplitOptions.RemoveEmptyEntries); LeftItems.Clear(); RightItems.Clear(); Items ??= Enumerable.Empty <SelectedItem>(); // 左侧移除 LeftItems.AddRange(Items); LeftItems.RemoveAll(i => list.Any(l => l == i.Value)); // 右侧插入 foreach (var t in list) { var item = Items.FirstOrDefault(i => i.Value == t); if (item != null) { RightItems.Add(item); } } }
private void MoveToLeft(ListItemViewModel item) { if (item != null) { RightItems.Remove(item); LeftItems.Add(item); } }
/// <summary> /// OnInitialized 方法 /// </summary> protected override void OnInitialized() { base.OnInitialized(); if (Items != null) { LeftItems.AddRange(Items.Where(i => !i.Active)); RightItems.AddRange(Items.Where(i => i.Active)); } }
private void ResetItems() { LeftItems.Clear(); RightItems.Clear(); if (Items != null) { LeftItems.AddRange(Items.Where(i => !i.Active)); } if (Items != null) { RightItems.AddRange(Items.Where(i => i.Active)); } }
protected override void OnInitialized(EventArgs e) { base.OnInitialized(e); DataContext = this; LeftItems.Add(new DataItem("Home", true, new HomePage())); LeftItems.Add(new DataItem("Intro to ECE", true, new BaseInfo())); LeftItems.Add(new DataItem("HOD's Welcome", true, new HODpage())); LeftItems.Add(new DataItem("Course Advisors", true, new ECE_Advisors())); LeftItems.Add(new DataItem("Contact Location", true, new ContactPage())); // Felix: I use these titles in Courses, so I put them in a common place. Course EeeCourse = new Course() { ProgramTitle = (string)Application.Current.FindResource("EEE_Courses_Title"), }; EeeCourse.readJSON(new Uri("pack://application:,,,/Resources/eeeCourseInfo.json")); Course CseCourse = new Course() { ProgramTitle = (string)Application.Current.FindResource("CSE_Courses_Title"), }; CseCourse.readJSON(new Uri("pack://application:,,,/Resources/cseCourseInfo.json")); Course SeCourse = new Course() { ProgramTitle = (string)Application.Current.FindResource("SE_Courses_Title"), }; SeCourse.readJSON(new Uri("pack://application:,,,/Resources/seCourseInfo.json")); // Needed the colours in the Courses page, so put them in a common file (Resources>Colours.xaml). string cseColour = (string)Application.Current.FindResource("Colour_CSE_Str"); RightItems.Add(new DataItem("CSE Info", true, new CSEInfo(), cseColour)); RightItems.Add(new DataItem("CSE Courses", true, CseCourse, cseColour)); string eeeColour = (string)Application.Current.FindResource("Colour_EEE_Str"); RightItems.Add(new DataItem("EEE Info", true, new EEEInfo(), eeeColour)); RightItems.Add(new DataItem("EEE Courses", true, EeeCourse, eeeColour)); string seColour = (string)Application.Current.FindResource("Colour_SE_Str"); RightItems.Add(new DataItem("SE Info", true, new SEInfo(), seColour)); RightItems.Add(new DataItem("SE Courses", true, SeCourse, seColour)); }
/// <summary> /// 选中数据移动方法 /// </summary> private async Task TransferItems(List <SelectedItem> source, List <SelectedItem> target) { IsTransfer = true; if (!IsDisabled && Items != null) { var items = source.Where(i => i.Active).ToList(); source.RemoveAll(i => items.Contains(i)); target.AddRange(items); LeftItems.ForEach(i => { var item = Items.FirstOrDefault(item => item.Value == i.Value && item.Text == i.Text && item.GroupName == i.GroupName); if (item != null) { item.Active = false; } }); RightItems.ForEach(i => { var item = Items.FirstOrDefault(item => item.Value == i.Value && item.Text == i.Text && item.GroupName == i.GroupName); if (item != null) { item.Active = true; } }); // 回调 if (ItemsChanged.HasDelegate) { await ItemsChanged.InvokeAsync(Items); } else { StateHasChanged(); } } }
private void MapAndCompareCollections(IMDTreeItem Left, IMDTreeItem Right, ComparisonItem node) { IEnumerable <IMDTreeItem> LeftItems; IEnumerable <IMDTreeItem> RightItems; if (m_CurrentMode == MatchingMode.ByID) { LeftItems = from item in Left.ChildItems orderby item.Key, item.Text select item; RightItems = from item in Right.ChildItems orderby item.Key, item.Text select item; } else { LeftItems = from item in Left.ChildItems orderby item.Text, item.Text select item; RightItems = from item in Right.ChildItems orderby item.Text, item.Text select item; } var LeftList = LeftItems.ToArray <IMDTreeItem>(); var RightList = RightItems.ToArray <IMDTreeItem>(); int leftIdx = 0; int rightIdx = 0; int leftCount = LeftList.Length - 1; int rightCount = RightList.Length - 1; bool Modified = false; while (true) { if (leftIdx > leftCount) { rightIdx++; if (rightIdx > rightCount) { break; } var Item = RightList[rightIdx]; AddAndFillNewNode(null, Item, node); Modified = true; continue; } if (rightIdx > rightCount) { leftIdx++; if (leftIdx > leftCount) { break; } var Item = LeftList[leftIdx]; AddAndFillNewNode(Item, null, node); Modified = true; continue; } var LeftItem = LeftList[leftIdx]; var RightItem = RightList[rightIdx]; int?comparisonResult = CompareObjects(LeftItem, RightItem); if (comparisonResult == 0) { var addedNode = AddAndFillNewNode(LeftItem, RightItem, node); if (addedNode != null) { Modified = Modified || addedNode.IsDiffer; } leftIdx++; rightIdx++; } else if (comparisonResult < 0) { AddAndFillNewNode(LeftItem, null, node); Modified = true; leftIdx++; } else if (comparisonResult > 0) { AddAndFillNewNode(null, RightItem, node); Modified = true; rightIdx++; } else { AddAndFillNewNode(LeftItem, null, node); AddAndFillNewNode(null, RightItem, node); leftIdx++; rightIdx++; Modified = true; } } if (Modified) { node.IsDiffer = true; } }