开发者

Change ControlTemplate of ContentControl in View using MVVM

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜