如何在C#中通过WPF Modern UI中的按钮导航链接?
我正在使用。我有一个按钮和链接的问题 我试图通过按钮点击事件导航,我在“Home.xaml”中的代码如下如何在C#中通过WPF Modern UI中的按钮导航链接?,c#,wpf,xaml,modern-ui,C#,Wpf,Xaml,Modern Ui,我正在使用。我有一个按钮和链接的问题 我试图通过按钮点击事件导航,我在“Home.xaml”中的代码如下 private void addGameButton_Click(object sender, RoutedEventArgs e) { BBCodeBlock bs = new BBCodeBlock(); try { bs.LinkNavigator.Navigate(new Uri("pack://application:/Pages/AddGa
private void addGameButton_Click(object sender, RoutedEventArgs e)
{
BBCodeBlock bs = new BBCodeBlock();
try
{
bs.LinkNavigator.Navigate(new Uri("pack://application:/Pages/AddGame.xaml"), null);
}
catch (Exception error)
{
ModernDialog.ShowMessage(error.Message, FirstFloor.ModernUI.Resources.NavigationFailed, MessageBoxButton.OK);
}
}
mui:MainWindows.xaml中的链接可以很好地用于导航。但我想通过Home.xaml页面中的按钮导航到Home.xaml页面中的AddGame.xaml
我的文件结构如下,仅供参考
因此,请告诉我,我哪里做错了?bs.LinkNavigator.Navigate方法的第二个参数是source,不能为空。试试这个:
private void addGameButton_Click(object sender, RoutedEventArgs e)
{
BBCodeBlock bs = new BBCodeBlock();
try
{
bs.LinkNavigator.Navigate(new Uri("/Pages/AddGame.xaml", UriKind.Relative), this);
}
catch (Exception error)
{
ModernDialog.ShowMessage(error.Message, FirstFloor.ModernUI.Resources.NavigationFailed, MessageBoxButton.OK);
}
}
有趣的是,在我的环境中,以下代码起作用:
if (App.HasDashboardRole)
{
App.Current.Dispatcher.Invoke(new Action(() =>
{
var bs = new BBCodeBlock();
bs.LinkNavigator.Navigate(new Uri("/Pages/Dashboard.xaml", UriKind.Relative), this);
}));
}
else if (App.HasBarcodeBuilderRole)
{
App.Current.Dispatcher.Invoke(new Action(() =>
{
var bs = new BBCodeBlock();
bs.LinkNavigator.Navigate(new Uri("/Pages/BarcodeBuilderPage.xaml", UriKind.Relative), this);
}));
}
当此代码不存在时:
App.Current.Dispatcher.Invoke(new Action(() =>
{
var bs = new BBCodeBlock();
if (App.HasDashboardRole)
bs.LinkNavigator.Navigate(new Uri("/Pages/Dashboard.xaml", UriKind.Relative), this);
else if (App.HasBarcodeBuilderRole)
bs.LinkNavigator.Navigate(new Uri("/Pages/BarcodeBuilderPage.xaml", UriKind.Relative), this);
}));
请查看以确保Uri是正确的。我尝试了许多方法,但未能获得解决方案。甚至我也尝试过stackoverflow链接-[谢谢Lukas。你救了我的命。我如何激活链接,也就是mui:link。对不起,但我不知道你的意思:“…我如何激活链接…”我正在使用我在问题中提到的现代用户界面。现代用户界面使用链接进行导航。所以我正在询问这些链接。如下所示