在WPF中进行数据模板切换 [英] Datatemplate switching in WPF
本文介绍了在WPF中进行数据模板切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如 MVVM友好DataTemplate切换 [ ^ ]我想根据整数变量切换我的Usercontrols。
可悲的是,屏幕保持白色,我无法弄明白为什么
我是什么尝试过:
As described in MVVM Friendly DataTemplate switching[^] I wanted to Switch my Usercontrols depending on an integer variable.
Sadly, the screen stays white, and I cannot figure out why
What I have tried:
<Window.Resources>
<ControlTemplate x:Key="DeciderControl">
<userControls:DeciderControl/>
</ControlTemplate>
</Window.Resources>
<Grid>
<ListBox>
<ListBox.ItemTemplate>
<DataTemplate>
<Control x:Name="decider" Template="{StaticResource DeciderControl}"/>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding IntTest}" Value="1">
<Setter TargetName="decider" Property="Template" Value="{StaticResource DeciderControl}"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
IntTest始终为1,在构造函数中设置我的ViewModel。
userControl也可以工作 - 如果我只是在ListBox中显示它没关系。
IntTest is always 1, set in the Constructor of my ViewModel.
the userControl also works - if I just show it in the ListBox it's ok.
推荐答案
问这个作者文章,Pete O'Hanlon,在文章页面的评论与讨论部分加入讨论: MVVM友好的DataTemplate切换 [ ^ 。
点击添加评论或问题来提问。彼得会得到通知和更改来回答你。据我所知,他是一个非常敏感的人。
-SA
Ask the author of this article, Pete O'Hanlon, by joining the discussion at the "Comments and Discussions" section on the article page: MVVM Friendly DataTemplate switching[^].
Click "Add a Comment or Question" to ask your question. Peter will get a notification and a change to answer you. From what I know, he is quite a responsive person.
—SA
这篇关于在WPF中进行数据模板切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文