I'm trying to make a tab appear for every file opened via File Explorer.
Expectations: upon double click on the file, it should open up a new tab for that file
Reality: every time I open a file, the frame gets overwritten.
MainPage - contains tabs
TabbedMainPage - the workspace
App.cs:
protected override void OnFileActivated(FileActivatedEventArgs Args)
{
base.OnFileActivated(Args);
Frame RF = Window.Current.Content as Frame;
if (RF != null)
{
var Y = new FrameNavigationOptions();
Y.IsNavigationStackEnabled = false;
RF.NavigateToType(typeof(MainPage), Args, Y);
}
else
{
RF = new Frame();
Window.Current.Content = RF;
RF.Navigate(typeof(MainPage), Args);
Window.Current.Activate();
}
}
MainPage.cs:
protected override void OnNavigatedTo(NavigationEventArgs EvArgs)
{
//Catch file
base.OnNavigatedTo(EvArgs);
var Args = EvArgs.Parameter as IActivatedEventArgs;
var FArgs = Args as FileActivatedEventArgs;
if (Args != null && Args.Kind == ActivationKind.File)
{
//Write file properties
TabViewItem NewTabItem = new TabViewItem();
NewTabItem.Header = "New Tab";
NewTabItem.IconSource = new Microsoft.UI.Xaml.Controls.SymbolIconSource() { Symbol = Symbol.Document };
Frame RF = new Frame();
RF.Navigate(typeof(TabbedMainPage), Args);
NewTabItem.Content = RF;
TabbedView.TabItems.Add(NewTabItem);
TabbedView.UpdateLayout();
}
else { }
}
TabbedMainPage.cs:
protected override async void OnNavigatedTo(NavigationEventArgs EvArgs)
{
//Catch file
base.OnNavigatedTo(EvArgs);
var Args = EvArgs.Parameter as IActivatedEventArgs;
var FArgs = Args as FileActivatedEventArgs;
if (Args != null && Args.Kind == ActivationKind.File)
{
//Write file properties
TXTFile = FArgs.Files[0] as StorageFile;
var Str = await TXTFile.OpenReadAsync();
//Read file
REB.Document.LoadFromStream(TextSetOptions.FormatRtf, Str);
RTB.Document.LoadFromStream(TextSetOptions.FormatRtf, Str);
Str.Dispose();
HomePage.Visibility = Visibility.Collapsed;
CheckForSaving();
}
else { }
}