2

I am using WPF PRISM and looking for a graceful approach to add TabItem so that i can Navigate using RequestNavigate.

This i have already achieved using following piece of code but View1 and View2 are not the actual views in fact these are just helping to show Title.

regionManager.RegisterViewWithRegion("TabRegion", typeof(View1));
regionManager.RegisterViewWithRegion("TabRegion", typeof(View2));

The actual problem is that i have also defined regions inside DataTemplate which are there to render the actual views. Initially i had faced issue to let RegionManager know about my Regions defined inside DataTemplate but with the help of this great post i solved this issue.

Tab definition in XAML:

<TabControl prism:RegionManager.RegionName="TabRegion">
    <TabControl.ContentTemplate>
        <DataTemplate>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="1*" />
                    <ColumnDefinition Width="2" />
                    <ColumnDefinition Width="3*" />
                </Grid.ColumnDefinitions>
                <ContentControl Grid.Column="0" prism:RegionManager.RegionName="TabNavigationRegion" prism:RegionManager.RegionManager="{Binding Path=DataContext.RegionManager, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" />
                <GridSplitter Grid.Column="1" HorizontalAlignment="Stretch" />
                <ContentControl Grid.Column="2" prism:RegionManager.RegionName="TabContentRegion" prism:RegionManager.RegionManager="{Binding Path=DataContext.RegionManager, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" />
            </Grid>
        </DataTemplate>
    </TabControl.ContentTemplate>
    <TabControl.ItemContainerStyle>
        <Style TargetType="{x:Type TabItem}">
            <Setter Property="Header" Value="{Binding RelativeSource={RelativeSource Self}, Path=Content.DataContext.TabModel.Title}" />
        </Style>
    </TabControl.ItemContainerStyle>
</TabControl>

Kindly suggest the best possible solution or any other efficient way to this problem?

4

1 回答 1

0

我的 PluralSight 课程题为“棱镜问题和解决方案:掌握 TabControl”,向您展示了如何解决这个问题。

https://app.pluralsight.com/library/courses/prism-mastering-tabcontrol/table-of-contents

您必须扩展 Prism 以允许将 RequestNavigate 与 TabControl 一起使用。

另外,我的建议是删除 DataTemplates 并只使用 Views (UserControls)。

于 2016-02-22T16:19:37.527 回答