[英]Dynamically changing content of ContentControl via trigger
我需要基于ViewModel中的布尔值在两个视图之间动态切换。
我认为这很简单:
<ContentControl>
<ContentControl.Style>
<Style TargetType="ContentControl">
<Setter Property="Content" Value="{StaticResource View1}" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsShowingView2}">
<Setter Property="Content" Value="{StaticResource View2}" />
</DataTrigger>
</Style.Triggers>
</Style>
</ContentControl.Style>
</ContentControl>
但是,即使IsShowingView2
始终为true,也不会显示View2
。
有任何想法吗? 我可以找到的所有示例似乎都在更改ContentTemplate,但是我不需要这样做。 我只想要不同的内容。
您实际上并没有为DataTrigger
设置值
<DataTrigger Binding="{Binding IsShowingView2}" Value="True">
<Setter Property="Content" Value="{StaticResource View2}" />
</DataTrigger>
还要在输出窗口中检查绑定错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.