导航到使用区域管理器在区域中声明的选项卡控件的选项卡

时间:2012-11-25 21:22:42

标签: c# wpf mvvm prism

我有一个具有制表符控件的usercontrol。在每个标签中,我声明了一些区域。

<TabControl Style="{DynamicResource HomeScreenTabControlStyle}">
            <TabItem Header="home"
                     Style="{DynamicResource HomeScreenTabItemStyle}">
                <StackPanel Orientation="Horizontal">
                    <StackPanel Name="BacklogPanel" Style="{DynamicResource FullLengthPanelStyle}"
                                prism:RegionManager.RegionName="{x:Static inf:RegionNames.FullLeftBoxRegion}">

                    </StackPanel>
                    <StackPanel Orientation="Vertical">
                        <StackPanel Name="ToDoPanel" Style="{DynamicResource HalfLengthPanelStyle}"
                                    prism:RegionManager.RegionName="{x:Static inf:RegionNames.HalfTopBoxRegion}">

                        </StackPanel>
                        <StackPanel Name="MeetingPanel" Style="{DynamicResource HalfLengthPanelStyle}"
                                    prism:RegionManager.RegionName="{x:Static inf:RegionNames.HalfBottomBoxRegion}">

                        </StackPanel>
                    </StackPanel> 
                    <StackPanel Name="SprintPanel" Style="{DynamicResource FullLengthPanelStyle}"
                                prism:RegionManager.RegionName="{x:Static inf:RegionNames.FullSecondLeftBoxRegion}">

                    </StackPanel>

                    <StackPanel Name="StoriesPanel" Style="{DynamicResource FullLengthPanelStyle}"
                                prism:RegionManager.RegionName="{x:Static inf:RegionNames.FullRightBoxRegion}">
                    </StackPanel>
                </StackPanel>
            </TabItem>
            <TabItem Header="sprints"
                     Style="{DynamicResource HomeScreenTabItemStyle}">
                <StackPanel Orientation="Horizontal">

                    <StackPanel Orientation="Horizontal">
                        <StackPanel Style="{DynamicResource FullLengthPanelStyle}"
                                prism:RegionManager.RegionName="{x:Static inf:RegionNames.SprintBacklog}">

                        </StackPanel>
                        <StackPanel Orientation="Vertical">
                            <StackPanel Style="{DynamicResource HalfLengthPanelStyle}"
                                    prism:RegionManager.RegionName="{x:Static inf:RegionNames.PeopleOnSprint}">

                            </StackPanel>
                            <StackPanel  Style="{DynamicResource HalfLengthPanelStyle}"
                                    prism:RegionManager.RegionName="{x:Static inf:RegionNames.SprintDetails}">

                            </StackPanel>
                        </StackPanel>
                        <StackPanel Style="{DynamicResource FullLengthPanelStyle}"
                                prism:RegionManager.RegionName="{x:Static inf:RegionNames.SprintTaskBacklog}">

                        </StackPanel>

                        <StackPanel  Style="{DynamicResource FullLengthPanelStyle}"
                                prism:RegionManager.RegionName="{x:Static inf:RegionNames.SprintMyTasks}">
                        </StackPanel>
                    </StackPanel>

                </StackPanel>
            </TabItem>

目前要导航到此HomeScreenView我正在做这样的事情......

_regionManager.RequestNavigate(RegionNames.ContentRegion, new Uri("/HomeScreenView", UriKind.Relative));

我是否可以传递给区域管理器,以便将Sprints选项卡设置为导航到的选项卡,而不是主页选项卡?

谢谢

1 个答案:

答案 0 :(得分:3)

可能最简单的方法是从这些TabItems创建视图。来自TabControl的区域。因此,您可以使用TabControlRegion导航到View,也可以使用INAVigationAware界面中的OnNavigateTo方法导航到HomeTabItemView和SpritsTabItemView

    public void OnNavigatedTo(NavigationContext navigationContext)
    {
        this.regionManager.RequestNavigate(RegionNames.TabControlRegion, new Uri(ViewNames.HomeTabItemView, UriKind.Relative));
        this.regionManager.RequestNavigate(RegionNames.TabControlRegion, new Uri(ViewNames.SpritsTabItemView, UriKind.Relative));
    }

TabControlRegion

<Window x:Class="Onii.Vespa.UI.Shell.Desktop.Shell"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Regions="clr-namespace:Microsoft.Practices.Prism.Regions;assembly=Microsoft.Practices.Prism" MinHeight="640" MinWidth="820" WindowState="Maximized">
<Grid Height="Auto">   
    <TabControl TabStripPlacement="Top" Regions:RegionManager.RegionName="TabControlRegion" HorizontalContentAlignment="Left" Margin="0,3,0,20" />
</Grid>

观点将是这样的:

<UserControl x:Class="MyNamespace.HomeTabItemView"
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:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:prism="clr-namespace:Microsoft.Practices.Prism.Regions;assembly=Microsoft.Practices.Prism"
mc:Ignorable="d" 
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
   <StackPanel Orientation="Horizontal">
       <StackPanel Name="BacklogPanel" Style="{DynamicResource FullLengthPanelStyle}"
      prism:RegionManager.RegionName="{x:Static inf:RegionNames.FullLeftBoxRegion}">

       </StackPanel>
       <StackPanel Orientation="Vertical">
           <StackPanel Name="ToDoPanel" Style="{DynamicResource HalfLengthPanelStyle}"
          prism:RegionManager.RegionName="{x:Static inf:RegionNames.HalfTopBoxRegion}">

           </StackPanel>
           <StackPanel Name="MeetingPanel" Style="{DynamicResource HalfLengthPanelStyle}"
          prism:RegionManager.RegionName="{x:Static inf:RegionNames.HalfBottomBoxRegion}">

           </StackPanel>
       </StackPanel> 
       <StackPanel Name="SprintPanel" Style="{DynamicResource FullLengthPanelStyle}"
      prism:RegionManager.RegionName="{x:Static inf:RegionNames.FullSecondLeftBoxRegion}">

       </StackPanel>

       <StackPanel Name="StoriesPanel" Style="{DynamicResource FullLengthPanelStyle}"
      prism:RegionManager.RegionName="{x:Static inf:RegionNames.FullRightBoxRegion}">
       </StackPanel>
   </StackPanel>
</Grid>

不要忘记设置TabItems标题文本。你可以在shered TabItemStyle

中完成
<Style TargetType="{x:Type TabItem}">
    <Setter Property="Header" Value="{Binding Content.DataContext.TabHeaderText, RelativeSource={RelativeSource Self}}"/>
    ...

然后,在TabControlRegion中显示的视图中,可以轻松地将TabHeaderText属性添加到ViewModel。