|
| 1 | +using Microsoft.Toolkit.Uwp.UI.Controls; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Collections.ObjectModel; |
| 4 | +using Windows.ApplicationModel.Core; |
| 5 | +using Windows.Foundation; |
| 6 | +using Windows.UI; |
| 7 | +using Windows.UI.ViewManagement; |
| 8 | +using Windows.UI.Xaml; |
| 9 | +using Windows.UI.Xaml.Controls; |
| 10 | + |
| 11 | +namespace Files |
| 12 | +{ |
| 13 | + /// <summary> |
| 14 | + /// The Instance Tabs Component for Project Mumbai |
| 15 | + /// </summary> |
| 16 | + public sealed partial class InstanceTabsView : Page |
| 17 | + { |
| 18 | + public static ObservableCollection<InstanceTabItem> instanceTabs { get; set; } = new ObservableCollection<InstanceTabItem>(); |
| 19 | + |
| 20 | + public InstanceTabsView() |
| 21 | + { |
| 22 | + this.InitializeComponent(); |
| 23 | + ApplicationView.PreferredLaunchViewSize = new Size(1080, 630); |
| 24 | + ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize; |
| 25 | + var CoreTitleBar = CoreApplication.GetCurrentView().TitleBar; |
| 26 | + CoreTitleBar.ExtendViewIntoTitleBar = true; |
| 27 | + CoreTitleBar.LayoutMetricsChanged += CoreTitleBar_LayoutMetricsChanged; ; |
| 28 | + CoreTitleBar_LayoutMetricsChanged(CoreTitleBar, null); |
| 29 | + TabStrip.Loaded += TabStrip_Loaded; |
| 30 | + |
| 31 | + |
| 32 | + var titleBar = ApplicationView.GetForCurrentView().TitleBar; |
| 33 | + titleBar.ButtonInactiveBackgroundColor = Color.FromArgb(0, 255, 255, 255); |
| 34 | + titleBar.ButtonHoverBackgroundColor = Color.FromArgb(75, 10, 10, 10); |
| 35 | + if (App.Current.RequestedTheme == ApplicationTheme.Dark) |
| 36 | + { |
| 37 | + titleBar.ButtonBackgroundColor = Color.FromArgb(0, 0, 0, 0); |
| 38 | + titleBar.ButtonForegroundColor = Colors.White; |
| 39 | + titleBar.ButtonHoverBackgroundColor = Color.FromArgb(75, 240, 240, 240); |
| 40 | + titleBar.BackgroundColor = Color.FromArgb(255, 25, 25, 25); |
| 41 | + } |
| 42 | + else if (App.Current.RequestedTheme == ApplicationTheme.Light) |
| 43 | + { |
| 44 | + titleBar.ButtonBackgroundColor = Color.FromArgb(0, 255, 255, 255); |
| 45 | + titleBar.ButtonForegroundColor = Colors.Black; |
| 46 | + titleBar.ButtonHoverBackgroundColor = Color.FromArgb(75, 155, 155, 155); |
| 47 | + } |
| 48 | + |
| 49 | + if (this.RequestedTheme == ElementTheme.Dark) |
| 50 | + { |
| 51 | + titleBar.ButtonForegroundColor = Colors.White; |
| 52 | + titleBar.ButtonHoverBackgroundColor = Color.FromArgb(75, 240, 240, 240); |
| 53 | + titleBar.BackgroundColor = Color.FromArgb(255, 25, 25, 25); |
| 54 | + } |
| 55 | + else if (this.RequestedTheme == ElementTheme.Light) |
| 56 | + { |
| 57 | + titleBar.ButtonForegroundColor = Colors.Black; |
| 58 | + titleBar.ButtonHoverBackgroundColor = Color.FromArgb(75, 155, 155, 155); |
| 59 | + titleBar.BackgroundColor = Colors.Transparent; |
| 60 | + } |
| 61 | + //instanceTabs.Clear(); |
| 62 | + |
| 63 | + } |
| 64 | + |
| 65 | + private void CoreTitleBar_LayoutMetricsChanged(CoreApplicationViewTitleBar sender, object args) |
| 66 | + { |
| 67 | + LeftPaddingColumn.Width = new GridLength((TabStrip.Items.Count * 150) + 32); |
| 68 | + RightPaddingColumn.Width = new GridLength(sender.SystemOverlayRightInset); |
| 69 | + } |
| 70 | + |
| 71 | + public static Grid ContentPresGrid { get; set; } = new Grid(); |
| 72 | + |
| 73 | + private void TabStrip_Loaded(object sender, RoutedEventArgs e) |
| 74 | + { |
| 75 | + instanceTabs.CollectionChanged += InstanceTabs_CollectionChanged; |
| 76 | + Frame FirstFrame = new Frame(); |
| 77 | + FirstFrame.Tag = 0; |
| 78 | + FirstFrame.Navigate(typeof(ProHome)); |
| 79 | + ContentPresGrid.Children.Add(FirstFrame); |
| 80 | + instanceTabs.Add(new InstanceTabItem() { HeaderText = "Favorites", SourcePage = "ProHome", index = 0, TabContent = FirstFrame }); |
| 81 | + } |
| 82 | + |
| 83 | + private void InstanceTabs_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) |
| 84 | + { |
| 85 | + var CoreTitleBar = CoreApplication.GetCurrentView().TitleBar; |
| 86 | + LeftPaddingColumn.Width = new GridLength((TabStrip.Items.Count * 250) + 32); |
| 87 | + RightPaddingColumn.Width = new GridLength(CoreTitleBar.SystemOverlayRightInset); |
| 88 | + //if(e.NewItems.Count > 0) |
| 89 | + //{ |
| 90 | + // List<TabViewItem> tabsFound = new List<TabViewItem>(); |
| 91 | + // Interacts.Interaction.FindChildren<TabViewItem>(tabsFound, InstanceTabsPage.Content as DependencyObject); |
| 92 | + |
| 93 | + // List<Frame> frames = new List<Frame>(); |
| 94 | + // Interacts.Interaction.FindChildren<Frame>(frames, InstanceTabsPage.Content as DependencyObject); |
| 95 | + // frames[0].Navigate((e.NewItems as List<InstanceTabItem>)[0].SourcePage); |
| 96 | + //} |
| 97 | + |
| 98 | + } |
| 99 | + |
| 100 | + |
| 101 | + |
| 102 | + private void NewTabButton_Click(object sender, RoutedEventArgs e) |
| 103 | + { |
| 104 | + Frame FirstFrame = new Frame(); |
| 105 | + FirstFrame.Tag = 0; |
| 106 | + FirstFrame.Navigate(typeof(ProHome)); |
| 107 | + ContentPresGrid.Children.Add(FirstFrame); |
| 108 | + instanceTabs.Add(new InstanceTabItem() { HeaderText = "Favorites", SourcePage = "ProHome", index = TabStrip.Items.Count, TabContent = FirstFrame }); |
| 109 | + TabStrip.SelectedItem = instanceTabs[instanceTabs.Count - 1]; |
| 110 | + } |
| 111 | + |
| 112 | + private void DragArea_Loaded(object sender, RoutedEventArgs e) |
| 113 | + { |
| 114 | + Window.Current.SetTitleBar((Grid)sender); |
| 115 | + } |
| 116 | + |
| 117 | + private void TabStrip_SelectionChanged(object sender, SelectionChangedEventArgs e) |
| 118 | + { |
| 119 | + List<TabViewItem> tabsFound = new List<TabViewItem>(); |
| 120 | + Interacts.Interaction.FindChildren<TabViewItem>(tabsFound, InstanceTabsPage.Content as DependencyObject); |
| 121 | + if ((e.AddedItems[0] as InstanceTabItem).SourcePage == "ProHome") |
| 122 | + { |
| 123 | + foreach(TabViewItem tvi in tabsFound) |
| 124 | + { |
| 125 | + if ((e.AddedItems[0] as InstanceTabItem).index == TabStrip.Items.IndexOf(tvi)) |
| 126 | + { |
| 127 | + // Applies below with selected Tab's information |
| 128 | + foreach(Frame instance in ContentPresGrid.Children) |
| 129 | + { |
| 130 | + // hide all other opened tab's content unless the instance belongs to the selected tab |
| 131 | + if( ((int) instance.Tag) != (e.AddedItems[0] as InstanceTabItem).index) |
| 132 | + { |
| 133 | + instance.Visibility = Visibility.Collapsed; |
| 134 | + } |
| 135 | + else |
| 136 | + { |
| 137 | + instance.Visibility = Visibility.Visible; |
| 138 | + } |
| 139 | + } |
| 140 | + return; |
| 141 | + } |
| 142 | + } |
| 143 | + } |
| 144 | + } |
| 145 | + |
| 146 | + private void TabStrip_TabClosing(object sender, TabClosingEventArgs e) |
| 147 | + { |
| 148 | + foreach(Frame instance in ContentPresGrid.Children) |
| 149 | + { |
| 150 | + if(((int) instance.Tag) == (e.Item as InstanceTabItem).index) |
| 151 | + { |
| 152 | + ContentPresGrid.Children.Remove(instance); |
| 153 | + return; |
| 154 | + } |
| 155 | + } |
| 156 | + } |
| 157 | + } |
| 158 | + |
| 159 | + public class InstanceTabItem |
| 160 | + { |
| 161 | + public string HeaderText { get; set; } |
| 162 | + public string SourcePage { get; set; } |
| 163 | + public int index { get; set; } |
| 164 | + public Frame TabContent { get; set; } |
| 165 | + |
| 166 | + |
| 167 | + } |
| 168 | +} |
0 commit comments