我正在尝试绑定ListView以设计时间数据,以便我可以使用Blend处理它,并且我已成功使用此方法。我创建一个ViewModel类,并在其构造函数中加载设计时数据。此数据通过ViewModel中的属性返回(此属性返回在构造函数中填充的列表对象)。然后在XAML中我创建一个像这样的CollectionViewSource
<CollectionViewSource
x:Name="PersonSource"
Source="{Binding Persons}"
d:Source="{Binding Persons, Source={d:DesignInstance Type=local:PersonViewModel, IsDesignTimeCreatable=True}}"/>
在我的ListView中,我现在要做的就是这个
<ListView x:Name="lstPatients" Grid.Row="1" ItemsSource="{Binding Source={StaticResource PersonSource}}">
这很好但我的问题是如果我不想在collectionViewSource中使用ViewModel及其属性。我们可以选择在后面的代码中设置ItemsSource,如果我想使用这种方法呢?在上面的例子中,我必须告诉{Binding Persons}中的ViewModel属性和Type = local:PersonViewModel中的ViewModel类,我想跳过这两个属性,并在设计时以某种方式设置ItemsSource属性。
答案 0 :(得分:0)
Blend可以做到。在这里打字太多了,但是从VS 2013开始,它就是内置的。
您所谈论的是设计和样本数据的组合。
祝你好运!