0

I have recently begun a learning project using WPF with VB.Net - This is the first time I haven't been able to find the answer I need, apologies if this is basic.

The following webpage describes how to handle navigation events within Modern UI, but I can't get it to work...

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

In 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

In 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

But the events don't seem to fire. I have tried including the Interface into the FirstFloor.ModernUI.Windows Namespace as follows:

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

But again, this doesn't work?

The standard WPF events - I.E. Initialized - work fine.

Thanks in advance!

Jiminy Cricket
  • 1,377
  • 2
  • 15
  • 24
  • Why did you select Modern UI? – paparazzo Aug 25 '14 at 16:04
  • Hi, I must admit that I stumbled across it, and liked the UI. Is there a more suitable alternative? Unfortunately, because I'm using the Express version of VS, I don't have access to Blend, myself. – Jiminy Cricket Aug 25 '14 at 16:06
  • Start with learning WPF and events and templates and .... First learn raw WPF. – paparazzo Aug 25 '14 at 16:08
  • Thanks for the advice. I don't have any problems with the standard WPF events - they're able to be handled as usual. I've implemented Icontent into the page class, but the events aren't firing – Jiminy Cricket Aug 25 '14 at 16:16

1 Answers1

1

You can implement the IContent interface on your content page class. e.g. If you have this on your main window:

<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>

then in Page1.xaml.vb you could implement 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

The On... methods will then be called as your content page is navigated to/from.

Mark
  • 8,140
  • 1
  • 14
  • 29
  • Hi, thanks for the reply. I managed to get that far, but I think my problem is in where I implement the Interface? It mentions on Codeplex to implement it in the Namespace, but I'm having trouble doing so. I have edited my question to show what I've tried. Thanks again. – Jiminy Cricket Aug 25 '14 at 17:10
  • @JiminyCricket If I am understanding your question updates correctly, you are defining your own `IContent` interface. What you need to do is implement the one in `FirstFloor.ModernUI.Windows` - so you just need the `Imports FirstFloor.ModernUI.Windows` shown in my sample above and don't need to define the `IContent` interface at all. – Mark Aug 25 '14 at 17:13