comunication of different NavigationContents(or ViewModels)?

Jul 12, 2010 at 2:29 AM

in my code:

KaoheSectionView.xaml

{

<Border>
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="MouseLeftButtonUp">
                    <nRoute:NavigateAction HandlerName="ContentContainer" Url="Views/MoniSectionSubject/ChoseTaskView/">     
                    </nRoute:NavigateAction>
                </i:EventTrigger>
            </i:Interaction.Triggers>
            <TextBlock> 

<!-- Here i want to show the return value of  "Views/MoniSectionSubject/ChoseTaskView/" --> 
            </TextBlock>

</Border>

<Canvas>
            <userControls:TipPanel>
                <nRoute:BrowsingContainer x:Name="BrowsingContainer">
                    <i:Interaction.Behaviors>
                        <nRoute:NavigationHandlerBehavior HandlerName="ContentContainer"/>
                    </i:Interaction.Behaviors>       
                </nRoute:BrowsingContainer>
            </userControls:TipPanel>
</Canvas>

}

in my ChoseTaskViewModel:

public class ChoseTaskViewModel : NavigationViewModelBase
    {
        public ObservableCollection<WQ_MoniScheme> Schemes { get; private set; }
        public ObservableCollection<WQ_MoniTask> Tasks { get; private set; }
        
        public WQ_MoniScheme CurrentScheme { get; set; }
        public WQ_MoniTask CurrentTask { get; set; }

}

 Schemes and  Tasks  bind to two ListBoxs,  CurrentScheme and CurrentTask bind to the selecteditem of the two ListBoxs, also are my return values of the ChoseTaskViewModel,

which should be show in the TextBlock of KaoheSectionView.xaml.

how to do this? use the Action?  thanks!!! 

i think it's the problem of comunication of different NavigationContents.

 

Coordinator
Jul 12, 2010 at 8:49 AM

Well, there are many ways to do inter ViewModel communications, but probably the best any easiest way to do so is to use Observable Channels - they allow you to communicate without the communicating parties having to keep direct references. Read about it here: http://www.orktane.com/Blog/post/2010/02/12/IObservable-based-Messaging-Broker-for-Silverlight.aspx and http://www.orktane.com/Blog/post/2010/04/13/nRoute-Now-More-Wholesome.aspx

Also depending on you your logical encapsulation of functionality, you could use something called ViewServices to accept input from another View/ViewModel. Have a look at how in this Sudoku game we use IBoxValueViewService to solicit user-input http://www.orktane.com/Blog/post/2010/01/23/iPhone-Sudoku-in-Silverlight-using-MVVM.aspx

Hope this helps,
Rishi