Kilazur
Kilazur

Reputation: 3188

ViewModelToViewConverter not working? Not even called?

I have a catel:TabControl with a custom template, in which I use ContentPresenter to... present the content. But it never appears.

The TabControl is binded to a ObservableCollection of viewModels (inheriting a custom base one).

I don't know what I'm doing wrong in this XAML, but there sure is something; or at least if there's not, I'll know I have to look at my code or something.

<catel:TabControl ItemsSource="{Binding ChildViewModels}" SelectedItem="{Binding SelectedChildViewModel, Mode=TwoWay}">
    <TabControl.Template>
        <ControlTemplate TargetType="{x:Type TabControl}">
            <Grid HorizontalAlignment="Stretch">
                <TabPanel IsItemsHost="True"/>
                <ContentPresenter Content="{Binding SelectedChildViewModel, Converter={catel:ViewModelToViewConverter}}"/>
            </Grid>
        </ControlTemplate>
    </TabControl.Template>
</catel:TabControl>

Upvotes: 0

Views: 171

Answers (1)

Geert van Horrik
Geert van Horrik

Reputation: 5724

I recommend to use the LazyLoading mode on the TabControl. In that case, you will only instantiate views when they are really required.

Unless you really need dynamic tabs, I recommend to just embed views and user controls inside the tab control:

<TabItem Header="Item 2">
    <views:MyView2 />
</TabItem>

<TabItem Header="Item 3">
    <views:MyView3 />
</TabItem>

<TabItem Header="Item 4">
    <views:MyView4 />
</TabItem>

Note that in order to create the behavior (LazyLoading, EagerLoader, etc), Catel implements a custom version of the TabControl which might interfere with your ContentPresenter.

Upvotes: 1

Related Questions