我最近开始了一个使用WPF和VB.Net的学习项目 - 这是我第一次找不到我需要的答案,如果这是基本的话,道歉。
以下网页介绍了如何在Modern UI中处理导航事件,但我无法让它工作......
在MainWindow中:
Public Interface Icontent
Sub OnFragmentNavigation(e As FragmentNavigationEventArgs)
Sub OnNavigatedFrom(e As NavigationEventArgs)
Sub OnNavigatedTo(e As NavigationEventArgs)
Sub OnNavigatingFrom(e As NavigatingCancelEventArgs)
End Interface
在Page:
Public Class Page1
Implements Icontent
Public Sub OnFragmentNavigation(e As FragmentNavigationEventArgs) Implements Icontent.OnFragmentNavigation
Debug.WriteLine("Yes")
End Sub
Public Sub OnNavigatedFrom(e As NavigationEventArgs) Implements Icontent.OnNavigatedFrom
Debug.WriteLine("Yes")
End Sub
Public Sub OnNavigatedTo(e As NavigationEventArgs) Implements Icontent.OnNavigatedTo
Debug.WriteLine("Yes")
End Sub
Public Sub OnNavigatingFrom(e As NavigatingCancelEventArgs) Implements Icontent.OnNavigatingFrom
Debug.WriteLine("Yes")
End Sub
End Class
但事件似乎没有发生。我尝试将Interface包含到FirstFloor.ModernUI.Windows命名空间中,如下所示:
Namespace FirstFloor.ModernUI.Windows
Public Interface Icontent
Sub OnFragmentNavigation(e As FragmentNavigationEventArgs)
Sub OnNavigatedFrom(e As NavigationEventArgs)
Sub OnNavigatedTo(e As NavigationEventArgs)
Sub OnNavigatingFrom(e As NavigatingCancelEventArgs)
End Interface
End Namespace
但同样,这不起作用?
标准WPF活动 - I.E.初始化 - 工作正常。
提前致谢!
答案 0 :(得分:1)
您可以在内容页面类上实现IContent
界面。例如如果你在主窗口上有这个:
<mui:ModernWindow x:Class="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="MainWindow" Height="350" Width="525"
ContentSource="/Page1.xaml">
</mui:ModernWindow>
然后在Page1.xaml.vb
中您可以实施IContent
:
Imports FirstFloor.ModernUI.Windows
Public Class Page1
Implements IContent
Public Sub OnFragmentNavigation(e As Navigation.FragmentNavigationEventArgs) Implements IContent.OnFragmentNavigation
Debug.WriteLine("OnFragmentNavigation")
End Sub
Public Sub OnNavigatedFrom(e As Navigation.NavigationEventArgs) Implements IContent.OnNavigatedFrom
Debug.WriteLine("OnNavigatedFrom")
End Sub
Public Sub OnNavigatedTo(e As Navigation.NavigationEventArgs) Implements IContent.OnNavigatedTo
Debug.WriteLine("OnNavigatedTo")
End Sub
Public Sub OnNavigatingFrom(e As Navigation.NavigatingCancelEventArgs) Implements IContent.OnNavigatingFrom
Debug.WriteLine("OnNavigatingFrom")
End Sub
End Class
随着您的内容页面导航到/来自,将调用On...
方法。