0

我最近开始了一个使用带有 VB.Net 的 WPF 的学习项目 - 这是我第一次无法找到我需要的答案,如果这是基本的,请道歉。

以下网页描述了如何在现代 UI 中处理导航事件,但我无法让它工作......

https://mui.codeplex.com/wikipage?title=Handle%20navigation%20events%20in%20your%20content&referringTitle=Documentation

在主窗口中:

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

在页面中:

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

但这些事件似乎并没有发生。我尝试将接口包含到 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 事件 - IE Initialized - 工作正常。

提前致谢!

4

1 回答 1

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...方法将在您的内容页面被导航到/从时被调用。

于 2014-08-25T17:03:23.947 回答