wpf 现代 UI 如何从另一个链接转到另一个页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28249707/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Modern UI how to go to another page from another link
提问by Kokombads
I am currently using Modern UI from CodePlex. It is great and easy to use but there are some classes and events that I am not familiar with. Example: I have two GroupLinks named "Patients" and "Configurations". There are several pages in each of the GroupLinks. I tried to navigate from one page to another using a button click event. It worked. But when I tried navigating from Page1 of GroupLink2 to Page1 of GroupLink1, it still worked, but the problem was the active GroupLink remained in GroupLink2 instead of GroupLink1 just like the screenshots show below:
我目前正在使用 CodePlex 的现代 UI。它很棒且易于使用,但有一些我不熟悉的类和事件。示例:我有两个名为“Patients”和“Configurations”的 GroupLink。每个 GroupLinks 中有几个页面。我尝试使用按钮单击事件从一个页面导航到另一个页面。有效。但是当我尝试从 GroupLink2 的 Page1 导航到 GroupLink1 的 Page1 时,它仍然有效,但问题是活动的 GroupLink 保留在 GroupLink2 而不是 GroupLink1 中,如下面的屏幕截图所示:




Btw, I used the code behind to navigate from Allergies(IrritantPage) to PatientsPage:
顺便说一句,我使用后面的代码从 Allergies(IrritantPage) 导航到PatientsPage:
private void FilterControl_OnToPatientClick(object sender, RoutedEventArgs e)
{
NavigationCommands.GoToPage.Execute("/MainContents/PatientGridPage.xaml", this);
}
So how do I solve this?
那么我该如何解决这个问题呢?
here are my MainWindow, Patient's Tab Page and Configuration's List Page
这是我的主窗口、患者标签页和配置列表页
MODERN WINDOW (Main Window)
现代窗口(主窗口)
<mui:ModernWindow x:Class="DentalProto.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mui="http://firstfloorsoftware.com/ModernUI"
Title="Dental" IsTitleVisible="True"
WindowStartupLocation="CenterScreen"
Width="1200"
Height="720"
ContentSource="/Pages/MainTabPage.xaml"
Closing="MainWindow_OnClosing"
>
<mui:ModernWindow.MenuLinkGroups>
<mui:LinkGroup DisplayName="User Name">
<mui:LinkGroup.Links>
<mui:Link DisplayName="Patients" Source="/Pages/MainTabPage.xaml" />
<mui:Link DisplayName="Configurations" Source="/Pages/ConfigurationsListNav.xaml" />
</mui:LinkGroup.Links>
</mui:LinkGroup>
<mui:LinkGroup DisplayName="settings" GroupKey="settings">
<mui:LinkGroup.Links>
<mui:Link DisplayName="software" Source="/Pages/SettingsPage.xaml" />
</mui:LinkGroup.Links>
</mui:LinkGroup>
</mui:ModernWindow.MenuLinkGroups>
<mui:ModernWindow.TitleLinks>
<mui:Link DisplayName="settings" Source="/Pages/SettingsPage.xaml" />
<mui:Link DisplayName="help" Source="https://www.facebook.com/" />
</mui:ModernWindow.TitleLinks>
</mui:ModernWindow>
MAINTAB PAGE (Patient Page)
MAINTAB 页面(患者页面)
<UserControl x:Class="DentalProto.Pages.MainTabPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mui="http://firstfloorsoftware.com/ModernUI"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="1280">
<Grid >
<!-- TODO: set @SelectedSource -->
<mui:ModernTab Layout="Tab">
<mui:ModernTab.Links>
<!-- TODO: set @Source -->
<mui:Link DisplayName="Patient" Source="/MainContents/PatientGridPage.xaml" />
<mui:Link DisplayName="Treatment Record" Source="/MainContents/TreatmentFillInPage.xaml"/>
</mui:ModernTab.Links>
</mui:ModernTab>
</Grid>
</UserControl>
CONFIGURATIONLISTNAV (Configurations' Page)
CONFIGURATIONLISTNAV(配置页面)
<UserControl x:Class="DentalProto.Pages.ConfigurationsListNav"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mui="http://firstfloorsoftware.com/ModernUI"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid Style="{StaticResource ContentRoot}">
<!-- TODO: set @SelectedSource -->
<mui:ModernTab Layout="List">
<mui:ModernTab.Links>
<!-- TODO: set @Source -->
<mui:Link DisplayName="Allergies" Source="/MainContents/IrritantGridPage.xaml"/>
<mui:Link DisplayName="Health Diseases" Source="/MainContents/HealthDiseaseGridPage.xaml"/>
<mui:Link DisplayName="Mouth Diseases" Source="/MainContents/MouthDiseaseGridPage.xaml"/>
<mui:Link DisplayName="Procedures" Source="/MainContents/ProcedureGridPage.xaml"/>
<mui:Link DisplayName="Dentists" Source="/MainContents/DentistGridPage.xaml"/>
</mui:ModernTab.Links>
</mui:ModernTab>
</Grid>
</UserControl>
回答by corradolab
You are mixing "page" navigation with "tab" navigation inside the ModernTab control.
您在 ModernTab 控件中混合了“页面”导航和“选项卡”导航。
If you call NavigationCommands.GoToPage.Executeinside a ModernTab control you are changing the current "tab", not the current "page".
如果您NavigationCommands.GoToPage.Execute在 ModernTab 控件内部调用,您将更改当前的“选项卡”,而不是当前的“页面”。
To change the top level page you can use:
要更改顶级页面,您可以使用:
IInputElement target = NavigationHelper.FindFrame("_top", this);
NavigationCommands.GoToPage.Execute("/Pages/BasicPage1.xaml", target);
If the new page is another ModernTab and you want to select a different tab then the default one, then you have to put in place some extra code. In example you could pass parameters to the new page. Se this SOanswer.
如果新页面是另一个 ModernTab,并且您想要选择一个不同的选项卡而不是默认选项卡,那么您必须放置一些额外的代码。例如,您可以将参数传递给新页面。看到这个SO答案。
回答by Aaron Reed
For anyone that may be struggling with this, set this in your MainWindow.cs constructor:
对于可能为此苦苦挣扎的任何人,请在 MainWindow.cs 构造函数中设置:
Application.Current.MainWindow = this;
Then in the part of your application where you want to navigate to a page, run this:
然后在您要导航到页面的应用程序部分中,运行以下命令:
IInputElement target = NavigationHelper.FindFrame("_top", Application.Current.MainWindow);
NavigationCommands.GoToPage.Execute("/NameOfYourPage.xaml", target);

