You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
By clicking “Sign up for GitHub”, you agree to our
terms of service
and
privacy statement
. We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
When you host a region in a
TabControl
, the views and view models that are in the region don't have control over the header text. I would like PRISM to have support for this out of the box.
I know
@brianlagunas
discussed in his excellent Pluralsight Course ("Prism Problems & Solutions: Mastering TabControl"), that you can easily set the header text of a TabControl using a style. Even though, that is a very simple solution to the problem, I do think it has some downsides: (1) you always need to customize all the
TabControl
s that you use with a custom style, which leads to code duplication, and (2) it is "untyped", there is nothing in the view or view model stating that it's participating in being hosted in a TabControl.
We have a
behavior
that enables a view model to be
"region hosted in TabControl"-aware
so you can implement that, and give the view model that information back to PRISM, similar to how IActiveAware works, and all of its friends.
Could this be part of PRISM?
Thanks for the idea, but this is not something we will be adding to Prism. You don't need to customize all the TabControls you use. Only the TabCOntrols being used as a region. Also, there really isn't any code duplication, you can create one style and use it for every TabControl that is a region, thus reusing that style across your application. Yes, it is untyped, by that is the nature of binding in WPF in general.
I think your behavior is a great approach to simplifying things for you, but the interface members are too limiting for mass usage. For one, TabItem.Header is of type object, so not just text can go in there. This implementation would limit that and would actually reduce functionality which is not something we want to do.
I think leaving it as-is would be the best option as it leaves it wide open for the developer to choose how they want to implement it to fit their application requirements.
Hi guys, could you please share an example?
I'm using a
TabControl
as a named region, when the views are navigated to, the title isn't loaded. Here's what I've tried:
<TabControl
prism:RegionManager.RegionName="{x:Static common:Constants.AdminRegion}">
<TabControl.Resources>
<Style TargetType="{x:Type TabItem}">
<Setter Property="Header" Value="{Binding DataContext.Title, Source={RelativeSource Self}}"/>
<!-- OR -->
<Setter Property="Header" Value="{Binding Title}"/>
</Style>
</TabControl.Resources>
</TabControl>
@weitzhandler
The style that Brian Lagunas uses in his Pluralsight course can be found in the excercise files of his course. If you have that, you can check the complete example out there, but basically, it's this:
<Style TargetType="TabItem">
<Setter Property="Header" Value="{Binding DataContext.Title}" />
</Style>
So you were almost there ;)
I've also pasted the source for
ViewModelFromViewExtractor
into
the gist
, so that should be sufficient to reproduce the solution as I use it in my app (still today ;)). If you don't get it working, I can create an example for you, but probably the style should be sufficient to get it working for you. And is also simpler anyhow ;)
And BTW, maybe there is a way to include some title data in the navigation service journal, so we can show the breadcrumbs etc.
I'll look into it, but currently tab header is enough for me now.
Sorry, I don't have an account on that Slack workspace, and don't want one. We're moving away from WPF, in favor of a web frontend written in React. So there is no value for me to get involved more than I am now.
Having that said, I'm happy to answer a stackoverflow question, if you have one ;)
i want to open child window from MainWindow where child window having region where we can navigate
how to do that using Prism in WPF?
@weitzhandler
thank's but if i try to register region of any page other than main page its not comming in region.
here i am trying to show some Dialog which are having many ui to navigate, if i click on any button but my ui region is not able to register. how to do that?
i am very new to prism.