/// <summary> /// Adds user page into top navigation menu. /// </summary> /// <param name="page">Page which should be added to top navigation menu.</param> /// <param name="vm">ViewModel for page.</param> /// <param name="navMenuLabelKey">Localization key for label in navigation menu.</param> /// <param name="navMenuIconKey">Localization key for icon in navigation menu.</param> private void AddUserPage(UserControl page, BaseClosableVM vm, string navMenuLabelKey = "", string navMenuIconKey = "") { page.DataContext = vm; ContentPageData pageData = new ContentPageData(new NavMenuItemData() { IsDropdownItem = false, IsSelected = false }, navMenuLabelKey, navMenuIconKey, PageKind.UserPages, page, ChangePage); //vm.Closed += (object sender, EventArgs e) => { DelPageFromMenu(pageData); }; vm.Closed += delPageEventHandler; PagesData.Add(pageData); TopItemSource.Add(pageData.NavData); ResetSelectedItems(); MainContent = page; pageData.NavData.IsSelected = true; TitleKey = pageData.LocalizedKey; }
public MainWindowVM() { ContentPageData buf = new ContentPageData(new NavMenuItemData() { IsDropdownItem = false, IsSelected = false }, "#appSettingsMenu", "AppSettingsPageIcon", PageKind.Settings, new AppSettingsPage(), ChangePage); PagesData.Add(buf); BottomItemSource.Add(buf.NavData); ChangePage(buf); buf = new ContentPageData(new NavMenuItemData() { IsDropdownItem = false, IsSelected = false }, "#addBomberPageMenu", "AddBomberPageIcon", PageKind.Settings, (data) => { AddUserPage(new BomberPage(), new BomberPageVM(), "#NavMenuBomberPage", "BomberPageIcon"); }); PagesData.Add(buf); BottomItemSource.Insert(0, buf.NavData); buf = new ContentPageData(new NavMenuItemData() { IsDropdownItem = false, IsSelected = false }, "#addTransmitFilePageMenu", "AddTransmitFilePageIcon", PageKind.Settings, (data) => { AddUserPage(new TransmitFilePage(), new TransmitFilePageVM(), "#NavMenuTransmitFilePage", "TransmitFilePageIcon"); }); PagesData.Add(buf); BottomItemSource.Insert(0, buf.NavData); buf = new ContentPageData(new NavMenuItemData() { IsDropdownItem = false, IsSelected = false }, "#addTransmitPageMenu", "AddTransmitPageIcon", PageKind.Settings, (data) => { AddUserPage(new TransmitPage(), new TransmitPageVM(), "#NavMenuTransmitPage", "TransmitPageIcon"); }); PagesData.Add(buf); BottomItemSource.Insert(0, buf.NavData); Settings.Instance.Proxies.CollectionChanged += OnProxiesCollectionChanged; Settings.Instance.PropertyChanged += OnDevicePropertyChanged; PropertyChanged += TitleKey_PropertyChanged; Manager <LanguageCultureInfo> .StaticInstance.CultureChanged += Language_CultureChanged; Manager <ThemeCultureInfo> .StaticInstance.CultureChanged += Theme_CultureChanged; TitleKey_PropertyChanged(this, new PropertyChangedEventArgs("TitleKey")); }
private void OnProxiesCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add) { foreach (var el in e.NewItems) { if (el is IChannelProxy proxy) { //recievePage RecieveChannelPage recievePage = null; _context.Send((s) => { recievePage = new RecieveChannelPage(); recievePage.DataContext = new RecieveChannelPageVM(proxy); }, null); ContentPageData recievePageData = new ContentPageData(new NavMenuItemData() { IsDropdownItem = false, IsSelected = false }, "#NavMenuRecieveProxyPage", "RecievedProxyPageIcon", PageKind.Proxy, recievePage, ChangePage); PagesData.Add(recievePageData); //monitorPage MonitorChannelPage monitorPage = null; _context.Send((s) => { monitorPage = new MonitorChannelPage(); monitorPage.DataContext = new MonitorChannelPageVM(proxy); }, null); ContentPageData monitorPageData = new ContentPageData(new NavMenuItemData() { IsDropdownItem = false, IsSelected = false }, "#NavMenuMonitorProxyPage", "MonitorProxyPageIcon", PageKind.Proxy, monitorPage, ChangePage); PagesData.Add(monitorPageData); ContentPageDataForProxy channelViewData = new ContentPageDataForProxy(new NavMenuItemData() { IsDropdownItem = true, IsSelected = false }, "NavMenuProxyIcon", proxy, PageKind.Proxy); channelViewData.NavData.AddDropdownItem(recievePageData.NavData); channelViewData.NavData.AddDropdownItem(monitorPageData.NavData); PagesData.Add(channelViewData); _context.Post((s) => { int insertIndex = PagesData.Where(x => x.Kind == PageKind.Channel || x.Kind == PageKind.Proxy).Max(x => TopItemSource.IndexOf(x.NavData)); if (insertIndex < 0) { insertIndex = 0; } else { insertIndex++; } TopItemSource.Insert(insertIndex, channelViewData.NavData); }, null); } } } if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Reset) { ClearProxies(); } if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove) { var objectsToRemove = PagesData.Where(x => IsContentPageDataContainsProxies(x, e.OldItems)).Select(x => x.NavData); _context.Send((s) => { TopItemSource.RemoveAll(x => objectsToRemove.Contains(x)); }, null); if (e.OldItems != null) { foreach (var el in e.OldItems) { if (el is IChannelProxy proxy) { proxy.Dispose(); } } } } }
private void OnDevicePropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e != null && e.PropertyName != "Device") { return; } ClearChannels(); if (Settings.Instance.Device == null) { return; } Settings.Instance.Device.IsConnectedChanged += (object s, EventArgs args) => { if (s == Settings.Instance.Device) { if (Settings.Instance.Device.IsConnected) { OnDevicePropertyChanged(null, null); } else { ClearChannels(); } } }; if (!Settings.Instance.Device.IsConnected) { return; } //create views foreach (var el in Settings.Instance.Device.Channels.Reverse()) { //recievePage var recievePage = new RecieveChannelPage(); recievePage.DataContext = new RecieveChannelPageVM(el); ContentPageData recievePageData = new ContentPageData(new NavMenuItemData() { IsDropdownItem = false, IsSelected = false }, "#NavMenuRecieveChannelPage", "RecievedChannelPageIcon", PageKind.Channel, recievePage, ChangePage); PagesData.Add(recievePageData); //monitorPage var monitorPage = new MonitorChannelPage(); monitorPage.DataContext = new MonitorChannelPageVM(el); ContentPageData monitorPageData = new ContentPageData(new NavMenuItemData() { IsDropdownItem = false, IsSelected = false }, "#NavMenuMonitorChannelPage", "MonitorChannelPageIcon", PageKind.Channel, monitorPage, ChangePage); PagesData.Add(monitorPageData); ContentPageData channelViewData = new ContentPageData(new NavMenuItemData() { IsDropdownItem = true, IsSelected = false }, "#" + el.ToString() + "NavMenu", el.ToString() + "Icon", PageKind.Channel); channelViewData.NavData.AddDropdownItem(recievePageData.NavData); channelViewData.NavData.AddDropdownItem(monitorPageData.NavData); PagesData.Add(channelViewData); _context.Post((s) => { int insertIndex = PagesData.Where(x => x.Kind == PageKind.Channel).Max(x => TopItemSource.IndexOf(x.NavData)); if (insertIndex < 0) { insertIndex = 0; } TopItemSource.Insert(insertIndex, channelViewData.NavData); }, null); } }