How to DoSomething() and then navigate to Page.xaml by clicking button?

Mar 12, 2013 at 4:22 PM
since i need to do two thing when clicking button, i figure i could do it in code behind.

i try by creating click event that would do
  1. DoSomething()
  2. navigate to Page.xaml if DoSomething returns true.
i try
NavigationService nav = NavigationService.GetNavigationService(this);
nav.Navigate(new System.Uri("Page.xaml", UriKind.RelativeOrAbsolute));
but got runtime error.

i noticed that the template are using mvvm(is it?) pattern. but im not experience with that pattern, and there are no standard mvvm workflow that i can follow.

it would be wonderfull if i you could provide example in this pattern.

thanks.
Coordinator
Mar 12, 2013 at 9:11 PM
The NavigationService is not part of ModernUI, it's the standard service that works with WPF Frames, not with ModernFrame instances.

In your click event handler you can navigate the Frame by specifying the Source property in your code behind. Additionally you can do anything else in your event handler.
Mar 13, 2013 at 6:22 PM
Ok. Pardon me for asking, but how do i navigate to other pages in code behind?

You said "navigate the Frame by specifying the Source property in your code behind". Source property of what?

thanks.
Coordinator
Mar 13, 2013 at 11:31 PM
You'll need to get the reference of the ModernFrame instance you want to navigate. You can use the NavigationHelper.FindFrame for this purpose.

Assuming you are in an event handler method of a UserControl, the following snippet finds the ModernFrame hosting the UserControl (referenced by this) and navigates the frame to another page.
using FirstFloor.ModernUI.Windows;

private void Button_Click(object sender, RoutedEventArgs e)
{
  var frame = NavigationHelper.FindFrame(null, this);
  if (frame != null) {
    frame.Source = new Uri("Page.xaml", UriKind.Relative);
  }
}
Mar 14, 2013 at 2:29 AM
Thank you. saves me the trouble threading the source.
Apr 11, 2013 at 4:41 PM
I noticed a problem with this method.

If i navigate to a link in different link group, the active link group is not activated. Navigate through button command in xaml works though. Navigating in code behind doesnt update active link group. How can i navigate in code behind properly?

By the way, i found a links that might interest you(list of win 8 colors) http://www.creepyed.com/2012/09/windows-8-colors-hex-code/

Thanks.
Apr 11, 2013 at 5:09 PM
I tried this in button click event code behind without success.
            Button b = sender as Button;
            b.Command = NavigationCommands.GoToPage;
            b.CommandParameter = @"/Content/MyContent.xaml";
            b.CommandTarget = NavigationHelper.FindFrame(null, this);
            b.Command.Execute(null);
The page doesnt navigate at all.

Thanks.
Coordinator
Apr 11, 2013 at 5:47 PM
Your menu instance is not synced when navigating a frame in the code behind? That's weird. Can you post (or send) the source?
Apr 12, 2013 at 12:49 AM
Edited Apr 12, 2013 at 1:21 AM
I know why. I missed first "/" in my links. Example. "Content/ProtocolEntry.xaml" should be "/Content/ProtocolEntry.xaml"

Thank you and im truly sorry for bothering you.
Coordinator
Apr 12, 2013 at 12:54 AM
No worries. Good to hear it works as advertised.
Apr 19, 2013 at 1:45 AM
First, I wanted to say thanks for the work you have done with this. Very nice!

Second, in earlier post you said
"The NavigationService is not part of ModernUI, it's the standard service that works with WPF Frames, not with ModernFrame instances."
Given that what's the recommended way to pass parameters to a page, is it by passing query string data value in the URI?

Thanks in advance:)
Coordinator
Apr 20, 2013 at 1:22 PM
Pass parameters using fragments and use IContent.OnFragmentNavigation to retrieve the uri fragment. See also this thread.