Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
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.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?
My PluralSight course titled "Prism Problems and Solutions: Mastering the TabControl" shows you how to solve this.
https://app.pluralsight.com/library/courses/prism-mastering-tabcontrol/table-of-contents
You have to extend Prism to allow the use of RequestNavigate with a TabControl.
Also, my advice is to drop the DataTemplates and just use Views (UserControls).
–
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.