我有一个ViewModel的数据模板,其中的ItemsControl与CollectionViewSource绑定在一起(以便在xaml中进行排序)。
<DataTemplate x:Key="equipmentDataTemplate">
<Viewbox>
<Viewbox.Resources>
<CollectionViewSource x:Key="viewSource" Source="{Binding Modules}">
<CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="ID" Direction="Ascending"/>
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
</Viewbox.Resources>
<ItemsControl ItemsSource="{Binding Source={StaticResource viewSource}}"
Height="{DynamicResource equipmentHeight}"
ItemTemplate="{StaticResource moduleDataTemplate}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</Viewbox>
</DataTemplate>
我还设置了UserControl,其中所有这些均已定义为提供设计时数据
d:DataContext="{x:Static vm:DesignTimeHelper.Equipment}">
这基本上是一个静态属性,为我提供了一个EquipmentViewModel,其中包含ModuleViewModels(Equipment.Modules)列表。现在,只要我绑定到CollectionViewSource,设计时数据就不会显示在blend 3中。当我直接绑定到ViewModel集合时
<ItemsControl ItemsSource="{Binding Modules}"
我可以看到设计时数据。知道我能做什么吗?
最佳答案
去过那里(至少现在):)
这是我找到的解决方案。诀窍是覆盖CollectionViewSource设计时的源。我使用d:DesignSource
属性使用另一个静态资源设计时:
<Window.Resource>
<CollectionViewSource x:Key="ViewSource"
Source="{Binding ModelProperty}"
d:DesignSource="{{x:Static MyProg:DesignTimeData.MyList}">
<!-- Contents -->
</CollectionViewSource>
</Window.Resources>
<!-- No change to the using class -->
<ListBox ItemsSource="{Binding Source={StaticResource ViewSource}}">
</ListBox>
关于wpf - 当与CollectionViewSource绑定(bind)时,DesignTime数据未显示在Blend中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1447962/