Navigation?

36 views
Skip to first unread message

Gerhard Kreuzer

unread,
Feb 19, 2011, 12:58:42 PM2/19/11
to nro...@googlegroups.com
Hi,
 
my main window looks like this:
 

<

Window x:Class="MainWindow"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"

xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

xmlns:n="http://nRoute/schemas/2010/xaml"

mc:Ignorable="d"

Title="Starting 'Proof of Concept&quot;" Height="480" Width="598">

<i:Interaction.Behaviors>

<n:BridgeViewModelBehavior/>

</i:Interaction.Behaviors>

<StackPanel>

<n:StatefulContainer Url="Pages/Splash" >

<i:Interaction.Behaviors>

<n:NavigationHandlerBehavior IsDefaultHandler="True" />

</i:Interaction.Behaviors>

</n:StatefulContainer>

</StackPanel>

</

Window>

And, as expected, the splash view is shown.

Now, I want to navigate to some other view programmatically and I try to use this statement:

NavigationService

.Navigate(New NavigationRequest("Pages/Login/"))

The url exists, as far as I can see:

<

Assembly: DefineViewViewModel(GetType(MainWindow), GetType(ShellVM))>

<

Assembly: DefineViewViewModel(GetType(SplashView), GetType(ShellVM))>

<

Assembly: DefineViewViewModel(GetType(LoginView), GetType(ShellVM))>

<

Assembly: DefineViewViewModel(GetType(AdminRootView), GetType(AdminRootVM))>

'Associate urls with Views

<

Assembly: DefineNavigationContent("Pages/Splash/", GetType(SplashView))>

<

Assembly: DefineNavigationContent("Pages/Login/", GetType(LoginView))>

<

Assembly: DefineNavigationContent("Pages/AdminRoot/", GetType(AdminRootView))>

Now, I guess, that I get a new view into the Stateful container, using the same instance of ShellVM, but all I get is an error message, that there is no application wide default container specified.

So, why does my navigation command fail, and how and where should I specify this application wide container?

With best regards

Gerhard

Rishi Oberoi

unread,
Feb 19, 2011, 5:04:26 PM2/19/11
to nro...@googlegroups.com
Well, to define the application-wide default container you use the NavigationHandlerBehavior, in fact just as you have. However, I think you might have a timing issue, in that by the time the splash-screen is shown the MainWindow isn't loaded or is not properly hooked up. Why not put your programmatic navigation logic in the loaded event of the MainWindow?

Rishi

Gerhard Kreuzer

unread,
Feb 19, 2011, 5:07:10 PM2/19/11
to nro...@googlegroups.com
Hi Rishi,
 
ok, will try, thanks for the tip.
 
With best regards
 
Gerhard


Von: nro...@googlegroups.com [mailto:nro...@googlegroups.com] Im Auftrag von Rishi Oberoi
Gesendet: Samstag, 19. Februar 2011 23:04
An: nro...@googlegroups.com
Betreff: [nRoute] Re: Navigation?

Gerhard Kreuzer

unread,
Feb 20, 2011, 12:30:06 PM2/20/11
to nro...@googlegroups.com
Hi Rishi,
 
the logic resides in the view model, so I probably can use the OnLoaded override, but as I stated some days before, that code wasn't called by the nRout framework, for what reason ever. I don't wan't to put code in the UI, or the code behind files, cause this is one of the big advantages of MVVM, which I won't loose.
 
But: I get the async stuff running now usung RX and my application composition (mock) runs async and is able to report progress on screen. I do it in the constructor of the view model, because OnLoad ... you know.
 
But, maybe you can give me an idea, how programatically navigation should look, if I am certain, that this is formally correct, I can dive in and check out whats on. As long as I don't know, how do write down navigation statements, I feel like the director of a flee circus ....
 
With best regards
 
Gerhard 


Von: nro...@googlegroups.com [mailto:nro...@googlegroups.com] Im Auftrag von Rishi Oberoi
Gesendet: Samstag, 19. Februar 2011 23:04
An: nro...@googlegroups.com
Betreff: [nRoute] Re: Navigation?

Rishi Oberoi

unread,
Feb 23, 2011, 5:52:07 AM2/23/11
to nro...@googlegroups.com
I've said this many times but basically I generally don't believe in navigating through the ViewModel - generally it's best to do so in the View. Nonetheless, when you want do so programmatically use the NavigationService static class. It has a Navigate method, wherein you can also specify which navigation-container to use.

Rishi

Gerhard Kreuzer

unread,
Feb 27, 2011, 3:02:12 PM2/27/11
to nro...@googlegroups.com
Hi Rishi,
 
you were right, but what do you think is the best solution for that scenario:
 
I navigate to a view showing breaking company news. The user can decide to read it immedeately and click ok, or click cancle.
We don't want to show the news more than one time to the user, after he has clicked ok, so we need to note down, when a user clicks ok.
It is easy to do that, by calling some function of the view model, and within this function we can note down the user info and do navigation programmatically, which isn't that good you say.
We can do navigation in the UI, but than, we can't note down the user info, if the user has read the messages or not.
 
One way to combine the best of both sides can be an xxxAction, which can call a bool function and after returning of this function, one of two url were used, one for returning true and one for returning false.
 
We can think about that as something similar to the C# language construkt return (i>5:false;true).
<n:NavigateAfterDecicion Function="{Binding SomeBoolFunction}, TrueUrl="/Pages/TakeOneWay", FalseUrl="/Pages/OrTheOther"/>
 
Maybe this can be of interest for other, because there were often such points in workflows.
 
With best regards
 
Gerhard
 
 


Von: nro...@googlegroups.com [mailto:nro...@googlegroups.com] Im Auftrag von Rishi Oberoi
Gesendet: Mittwoch, 23. Februar 2011 11:52
An: nro...@googlegroups.com
Betreff: Re: AW: [nRoute] Re: Navigation?

Rishi Oberoi

unread,
Mar 2, 2011, 4:45:19 AM3/2/11
to nro...@googlegroups.com
This is already possible using condition behaviors, consider:
                    <i:EventTrigger EventName="Loaded">
                        <i:Interaction.Behaviors>
                            <ei:ConditionBehavior>
                                <ei:ConditionalExpression ForwardChaining="And">
                                    <ei:ComparisonCondition LeftOperand="{Binding SelectedIndex, ElementName=listBox}" Operator="Equal"
RightOperand="-1"/>
                                    <ei:ComparisonCondition LeftOperand="{Binding ItemsSource, ElementName=listBox}" Operator="NotEqual"
RightOperand="{x:Null}"/>
                                </ei:ConditionalExpression>
                            </ei:ConditionBehavior>
                        </i:Interaction.Behaviors>
                        <n:SetPropertyAction PropertyName="SelectedIndex" Value="0"/>
                    </i:EventTrigger>
Above, we've put a condition that when loaded if there is no selection and the listbox's ItemsSource is not null then select the first item. Also, FYI, there is a visual editor to support creating/editing such  conditional behaviors in Blend.

Rishi

Adrian Hara

unread,
Mar 2, 2011, 5:19:51 AM3/2/11
to nro...@googlegroups.com

Quick request: would be nice (for me at least) that when replying to the group we keep also the last message at least. Otherwise it might be hard to put the message into context, e.g. in this case I’m guessing this is about conditional navigation, but I’m not sure J

Freundliche Grüsse / Best regards

Adrian Hara
Cloud Developer
LinkedIn 


coresystems ag
Villa im Park | Dorfstrasse 69
5210 Windisch | Switzerland


Phone +41 56 500 22 22
Fax +41 56 444 20 50
Infoline +41 848 088 088
www.coresystems.ch
www.coresuite.com
follow us on
twitter

Visit us at CeBIT:
SAP Partner Booth: Hall 5, Booth A18
Cloud Computing: Hall 4, Booth A58
OS X Business Park: Hall 2, Booth A20
Microsoft Booth: Hall 4, Booth P47

The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and / or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.

Reply all
Reply to author
Forward
0 new messages