Reputation: 385
I want to change frame, but I get this exception:
Navigation:
Frame rootFrame = new Frame();
rootFrame.Navigate(typeof(ScoreWindow), null, new EntranceNavigationTransitionInfo());
Exception appears on constructor:
public ScoreWindow()
{
this.InitializeComponent();
results = new List<Result>();
playerList = new();
LoadData();
var _resultsView = ConvertToView();
sfDataGrid.ItemsSource = _resultsView;
}
Thanks for answers in advance and happy holidays!
P.S. Thanks to Raymond, I detected this message:
WinUI: Error creating second Desktop Window on the current process. No more than one Desktop Window is allowed per process.
There is another question: how to change current frame to other? I mean, I have login view, user logged in successfully and want to see data/other things.
Upvotes: 2
Views: 925
Reputation: 385
After a little break, I understood what I did wrong. There is a way how to navigate between pages.
Rule #1: In WinUI, you have only one active window, and it's MainWindow. Always. If you want to change layout, you have to use Frames.
In MainWindow.xaml, you write this:
<Grid>
<Frame x:Name="mainFrame"/>
</Grid>
Element "Frame" give ability to navigate between pages.
Then switch to MainWindow.xaml.cs and in constructor have to be something like this:
public MainWindow()
{
InitializeComponent();
mainFrame.Navigate(typeof(NameOfYourPage));
}
It will immediately activate your page.
Then, if you want to navigate from page to page, write in control of page this:
Frame.Navigate(typeof(NameOfYourPage), null, new EntranceNavigationTransitionInfo());
The third parameter is animation, but I didn't notice changes.
More information you can find here:
Upvotes: 2