2013-12-08 65 views
0

我使用的样品从http://www.mindscapehq.com/blog/index.php/2013/09/11/caliburn-micro-part-6-introduction-to-screens-and-conductors/从一个屏幕导航到另一个在卡利

有一个AppViewModel其中其它的ViewModels通过调用ActivateItem激活。

示例正在为我工​​作:我可以看到相应的视图。

我现在想要从另一个ViewModel激活一个ViewModel。它被实例化,但不显示相应的视图。

如何从“RedScreenViewModel”激活“GreenScreenViewModel”?

APPVIEW:

<UserControl x:Class="CaliburnMicroApp_Navigation.AppView" 
      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"> 
    <DockPanel Background="LightBlue" MinHeight="400" MinWidth="400"> 
    <StackPanel Orientation="Horizontal" DockPanel.Dock="Top" HorizontalAlignment="Center"> 
     <Button x:Name="ShowRedScreen" Content="Red" Width="50" /> 
     <Button x:Name="ShowGreenScreen" Content="Green" Width="50" Margin="12,0,0,0" /> 
     <Button x:Name="ShowBlueScreen" Content="Blue" Width="50" Margin="12,0,0,0" /> 
    </StackPanel> 
    <ContentControl x:Name="ActiveItem" /> 
    </DockPanel> 
</UserControl> 

AppViewModel

public class AppViewModel : Conductor<object> 
{ 
    public void ShowRedScreen() 
    { 
    ActivateItem(new RedViewModel()); 
    } 

    public void ShowGreenScreen() 
    { 
    ActivateItem(new GreenViewModel()); 
    } 

    public void ShowBlueScreen() 
    { 
    ActivateItem(new BlueViewModel()); 
    } 
} 

RedViewModel - 这不显示GREENVIEW()

public class RedViewModel : Conductor<object> 
    { 
     public void DisplayGreen() 
     { 
      ActivateItem(new GrenViewModel()); 
     } 
    } 

RedView

<Grid Background="Red"> 
     <StackPanel> 
    <TextBlock Text="red" FontSize="48" FontWeight="Bold" Foreground="#3CA527" /> 
     <Button Name="DisplayGreen"> 
      <TextBlock >Next Screen</TextBlock> 
     </Button> 
     </StackPanel> 
    </Grid> 

回答

1

如果你想在你AppViewContentControl显示ActiveItem当你按下更改ButtonRedViewModel,你将需要使用EventAggregator从您RedViewModel传递消息给你的AppViewModel

Mindscape EventAggregator tutorial

+0

OMG我什至经历过那个教程。这一定会奏效。 –

+0

@MalcolmFrexner - 哈哈,这些东西很容易在你工作了一段时间或被“分区”时错过。 – 2013-12-09 08:34:58

+0

@Malcolm Frexner您是否最终通过事件聚合器使其工作? – liang

相关问题