This is a migrated thread and some comments may be shown as answers.

Use same ViewModel,change its data template

3 Answers 288 Views
TransitionControl
This is a migrated thread and some comments may be shown as answers.
Tomwe
Top achievements
Rank 1
Tomwe asked on 15 Dec 2012, 08:41 AM
Hi,

I need to change the selected data template based on the state of the view model(the binding)
Here is my Xaml
(the content always point to "MainViewModel")

<telerik:RadTransitionControl

Name="radTransitionControl1"

ContentTemplateSelector="{StaticResource pageTemplateSelector}"

Transition="{Binding Transition}"

Content="{Binding}">

 

</telerik:RadTransitionControl>


Thanks in advance

3 Answers, 1 is accepted

Sort by
0
Ivo
Telerik team
answered on 18 Dec 2012, 09:41 AM
Hello Tomwe,

The SelectTemplate method of the ContentTemplateSelector is called every time when the Content is changed. I believe that you won't be able to change the ContentTemplate using the ContentTemplateSelector without changing the Content property. I woud suggest you to change the approach you use to achieve the desired behavior. Can you give us more details on your scenario so we can assist you and give you guidelines on this?

Kind regards,
Ivo
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Tomwe
Top achievements
Rank 1
answered on 26 Jan 2013, 08:39 AM

The solution was to bind the Content to the state of the main view model
where states represented as other  view models
0
Ramon
Top achievements
Rank 1
answered on 20 Mar 2014, 04:15 PM
I used an enum for state changing
here is a sample

<DataTemplate x:Key="ListUserDataTemplate" >
    <userView:ListuserData />
</DataTemplate>
<DataTemplate x:Key="NonerDataTemplate">
    <Grid >
    </Grid>
</DataTemplate>
<DataTemplate x:Key="MapUserDataTemplate">
    <userMap:MapUserData/>
</DataTemplate>
 
<Style x:Key="ManWindowHolderStyle" TargetType="{x:Type ContentControl}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ContentControl}">
                <telerik:RadTransitionControl Content="{Binding}" Transition="PerspectiveRotation" Duration="00:00:00.7" x:Name="ContentWindow" />
                <ControlTemplate.Triggers>
                    <DataTrigger Binding="{Binding AppStateHelper.MainWindowType}" Value="ListUserType">
                        <Setter Property="ContentTemplate" Value="{StaticResource ListUserDataTemplate}" TargetName="ContentWindow" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding AppStateHelper.MainWindowType}" Value="MapUserType">
                        <Setter Property="ContentTemplate" Value="{StaticResource MapUserDataTemplate}" TargetName="ContentWindow"/>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding AppStateHelper.MainWindowType}" Value="None">
                        <Setter Property="ContentTemplate" Value="{StaticResource NonerDataTemplate}" TargetName="ContentWindow"/>
                    </DataTrigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>


and i used a  ContentControl with the style applyed bound to the enum, you can use instead a viewmodel

<ContentControl Content="{Binding AppStateHelper.MainWindowType}"
                           Style="{StaticResource ManWindowHolderStyle}" />
Tags
TransitionControl
Asked by
Tomwe
Top achievements
Rank 1
Answers by
Ivo
Telerik team
Tomwe
Top achievements
Rank 1
Ramon
Top achievements
Rank 1
Share this question
or