0

我有一个带有选项卡控件的用户控件。在每个选项卡中,我声明了一些区域。

<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 选项卡设置为导航到的选项卡,而不是主页选项卡?

谢谢

4

1 回答 1

3

可能最简单的方法也是从这些 TabItem 中创建视图。以及来自 TabControl 的区域。因此,您使用 TabControlRegion 导航到您的视图,并且可能在 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));
    }

选项卡控制区域

<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}}"/>
    ...

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

于 2012-11-25T22:17:58.897 回答