如何从ResourceDictionary类(WPF)导航到xaml页面



我有一个ResourceDictionary类,如下所示:

using System.Windows.Navigation;
using static myApp.filesXAML.Login;
namespace myApp.Clases
{
partial class functionsMenu : ResourceDictionary
{
private void imageCloseMyApp(object sender, MouseButtonEventArgs e)
{
NavigationService.Navigate(new Uri("filesXAML/Login.xaml", UriKind.Relative));
}
}
}

imageCloseMyApp函数是通过单击图像来调用的,我希望调用另一个页面。

在编译项目之前,我得到了以下错误:

严重性代码描述项目文件行状态已删除错误CS0120字段、方法或属性"NavigationService.Navigate(Uri("不是静态myAppH: \pro\Visual_Studio\myApp\myApp\Classes\FunctionsMenu.cs 35活动

我搜索了互联网,并尝试了以下选项:

Login page = new Login();         
page.NavigationService.Navigate(new Uri("filesXAML/Login.xaml",UriKind.RelativeOrAbsolute));
// or
NavigationService nav = NavigationService.GetNavigationService(Application.Current.Windows[0].Parent);
nav.Navigate(new Uri("filesXAML/Login.xaml", UriKind.Relative));

但都不起作用。

有什么建议或意见吗?

我已经实现了如下目标:

NavigationService nav = NavigationService.GetNavigationService((Grid)((Image)sender).Parent);
nav.Navigate(new Uri("filesXAML/Login.xaml", UriKind.Relative));

我引导自己理解以下线索:

如何从资源中的控件发送的事件中获得父控件

最新更新