This project is read-only.

OnNavigatedTo send to other page

Jun 6, 2013 at 12:53 PM
Hi. Got the following requirement. When entering a page need to know if a certain context exist. If it doesn't redirect the client to a certain page. Unfortunately can do the redirect part, so:

In order to do this I've got my shell shell with a link like <mui:Link Source="/View/SomeIndex" (...)
and that page implements the IContent. In the OnNavigatedTo got the following code:
use FirstFloor.ModernUI.Windows.Navigation;
public void OnNavigatedTo(NavigationEventArgs e)
    NavigationCommands.GoToPage.Execute("/View/ContextPage.xaml", null);
The NavigationCommand is executed but doesn't have any effect.

Does anybody have any suggestion?

Thank you
Jun 6, 2013 at 2:16 PM
Edited Jun 6, 2013 at 2:16 PM
Ok. Once again I'll answer myself! :)

I have done a workarround. Instead of invoking the navigation command I'm now finding the frame/window and set the contentsource to the url that I want. So:
    ModernWindow window = this.TryFindParent<ModernWindow>();
    window.ContentSource = new Uri("/View/ContextPage.xaml", UriKind.Relative);
Still, if anyone can figure it why the navigation command doesn't work, that will be great.

Sérgio Amorim
Jun 7, 2013 at 6:23 PM
My guess this doesn't work is that you try to change the content frame source while the frame source is being changed. You could move the NavigationCommand.GoToPage.Execute invocation to a Dispatcher.Invoke(() => {..}) call, so the invocation is deferred after the OnNavigated has completed.
Jun 11, 2013 at 11:57 AM
Excellent. It worked like a charm, thank you once again.

Just for future reference, in my example the invoke should be:
ModernWindow window = this.TryFindParent<ModernWindow>();
    NavigationCommands.GoToPage.Execute("/View/DebitosDirectos/EntidadesCredoras/AlterarContexto.xaml", window);
Aug 20, 2013 at 11:41 AM

I am also having a problem with this .

This is my code
public partial class Home : UserControl
    public string DeleteFilesExit;
    private MatchCollection ObjNameVerMc;
    public string DbObjVer;
    // globats end 
    private System.IO.FileSystemWatcher m_Watcher;

    public Home()

        ExtractPath = ConfigurationManager.AppSettings.Get("ExtractPath");
        AppUpdated = ConfigurationManager.AppSettings.Get("AppUpdated");


        if (!IsProcessOpen("BlueTray"))
        { ModernDialog.ShowMessage("BlueTray is not running please start it.", "BlueTray not found", MessageBoxButton.OK); }

        if (AppUpdated.Equals("true", StringComparison.Ordinal))
            MessageBoxResult AppUpdatedMSG = ModernDialog.ShowMessage("CoreExtract has been updated please update you settings", "CoreExtract Updated", MessageBoxButton.OK);

            if (AppUpdatedMSG == MessageBoxResult.OK)
                ModernWindow window = this.TryFindParent<ModernWindow>();
                    NavigationCommands.GoToPage.Execute("/Pages/ObjectVersions.xaml", window);



I have the using FirstFloor.ModernUI.Windows.Navigation; statment at the top o my code but I still get this error Error 2 'CoreExtract2.Pages.Home' does not contain a definition for 'TryFindParent' and no extension method 'TryFindParent' accepting a first argument of type 'CoreExtract2.Pages.Home' could be found (are you missing a using directive or an assembly reference?) C:\Users\justinfo\Documents\Visual Studio 2012\Projects\CoreExtract2\CoreExtract2\Pages\Home.xaml.cs 63 48 CoreExtract2 any ideas what is wrong ?
Sep 3, 2013 at 12:50 PM
The TryFindParent extension is here
Credits to Phillip Sumi
Sep 8, 2013 at 7:35 PM

im trying to do this from an mvvm end, however at that point the ViewModel is not an UI element. Any idea how this could work with Viewmodels?

Best Regards.
Sep 8, 2013 at 8:25 PM
Answeres my own question.

Easy solution by using Application.Current.Mainwi dow is a direct reference to the ModernWindow.
Sep 9, 2013 at 9:54 AM
If you're using MVVM pattern then what you're doing is not the right way. The ViewModel shoudn't know what the view is made of. If you want to initiate some action from the viewmodel that "interacts" with the view then expose some actions from the viewmodel in which the view can assign something to it:
public class MyViewModel 
    //The exposed action
    public Action<string> DefineWindowTitle;
    public void CommandImplementation() 
        If(DefineWindowTitle != null)
            DefineWindowTitle("Hello World");
            throw new InvalidOperationException("Do Something is not initialized");

public class MyView : Control
    private MyViewModel viewModel;
    private void Initialized()
        this.viewModel = new MyViewModel() {
            DefineWindowTitle = SetWindowTitle
    private void SetWindowTitle(string windowTitle)
        ModernWindow window = this.TryFindParent<ModernWindow>();
        window.Title = windowTitle;
Apr 1, 2014 at 4:45 AM

you have to change the target framework to .Net Framework 4.5
Aug 15, 2014 at 7:29 AM
Hey ,t like this
 var uri = new Uri("/Client.xxxxxxxxxx;component/Views/xxxxxxxxxxx.xaml", UriKind.Relative);
            NavigationCommands.GoToPage.Execute(uri, null);