2014-01-10 27 views
0

以下是從我的外殼的部分:如何設置基於的datacontext ContentControl中的元素的DataContext上同一用戶控件

 <StackPanel x:Name="stack" Orientation="Horizontal" Height="25" HorizontalAlignment="Right" Margin="0,4,0,0" Grid.Row="0"> 
      <Button DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type StackPanel}}, Path=DataContext}" Content="Back" prism:Click.Command="{Binding Path=GoBackCommand}"/> 
      <Button DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type StackPanel}}, Path=DataContext}" Content="Forward" prism:Click.Command="{Binding Path=GoForwardCommand}" Margin="10,0,0,0"/> 
     </StackPanel> 


     <ContentControl x:Name="ActionContent" prism:RegionManager.RegionName="{x:Static inf:RegionNames.WorkspaceRegion}" Grid.Row="1"> 
      <ContentControl.Template> 
      <ControlTemplate TargetType="ContentControl" >       
         <Grid > 
         <Controls:RoundedBox/>     
         <ContentPresenter Margin="10,0,10,0" Content="{TemplateBinding Content}" />       
         </Grid>      

        <ControlTemplate.Triggers> 
        <Trigger Property="HasContent" Value="false"> 
         <Setter Property="Visibility" Value="Collapsed" /> 
        </Trigger> 

        <DataTrigger Binding="{Binding ElementName=stack}"> 
          <Setter Property="DataContext" Value="{Binding RelativeSource={RelativeSource Self}, 
          Path=Content.DataContext}" /> 
         </DataTrigger> 

        </ControlTemplate.Triggers> 

      </ControlTemplate> 
     </ContentControl.Template> 

在ContentControl中視圖是從模塊(使用功能區選項卡)注入。我希望StackPanel內部的兩個按鈕可以使用ViewModels(DataContext)的注入視圖,用於向後和向前導航。

請幫助,謝謝!

回答

0

我會通過Prism Navigation Chapter有一個良好的閱讀開始,

以及如何使用navigation journal

編輯: 我不認爲你可以做你直接在XAML想要什麼,但我可以看到2個解決方法:

  • 定義命令,在shell視圖模型全球CompositeCommand,然後讓你的看法在導航時重新註冊並取消註冊他們自己的實現。
  • 定義一個新的區域,視圖可以注入自己的導航按鈕。

希望這可以幫助你。

+0

我的問題不同於你的想法。我想在所有模塊的所有視圖模型的常見外殼的導航按鈕,現在的問題是,這些按鈕如何從不同的視圖模型獲取命令(用於導航),因爲這些按鈕放置在外殼上,因爲視圖綁定在contentControl上,並且按鈕被放置在堆疊面板中 –

相關問題