开发者

Change ControlTemplate of ContentControl in View using MVVM

开发者 https://www.devze.com 2023-01-08 17:26 出处:网络
I have two resources Dock and Undock in my View which is a UserControl(Dock.xaml), Following is xaml code

I have two resources Dock and Undock in my View which is a UserControl(Dock.xaml), Following is xaml code

开发者_开发百科<Grid>
    <ContentControl Template="{StaticResource Dock}"/>   
</Grid>

In DockViewModel there is property called IsDocked,if its true i need to apply Dock otherwise Undock template

How to change the template in view using ViewModel.


<ContentControl>
        <ContentControl.Style>
            <Style TargetType="ContentControl">
                <Setter Property="ContentControl.Template"  Value="{StaticResource Dock}"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding IsDocked}" Value="False">
                        <Setter Property="ContentControl.Template"  Value="{StaticResource UnDock}"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </ContentControl.Style>
    </ContentControl>
0

精彩评论

暂无评论...
验证码 换一张
取 消