绑定 CollectionViewSource 时,DesignTime 数据未显示在 Blend 中 [英] DesignTime data not showing in Blend when bound against CollectionViewSource
问题描述
我有一个视图模型的数据模板,其中一个 itemscontrol 绑定到一个 CollectionViewSource(以在 xaml 中启用排序).
I have a datatemplate for a viewmodel where an itemscontrol is bound against a CollectionViewSource (to enable sorting in 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,其中所有这些都被定义为提供设计时数据
I have also setup the UserControl where all of this is defined to provide designtime data
d:DataContext="{x:Static vm:DesignTimeHelper.Equipment}">
这基本上是一个静态属性,它为我提供了一个 EquipmentViewModel,其中包含一个 ModuleViewModels (Equipment.Modules) 列表.现在只要我绑定到 CollectionViewSource 设计时数据就不会显示在混合 3 中.当我直接绑定到 ViewModel 集合时
This is basically a static property that gives me an EquipmentViewModel that has a list of ModuleViewModels (Equipment.Modules). Now as long as I bind to the CollectionViewSource the designtime data does not show up in blend 3. When I bind to the ViewModel collection directly
<ItemsControl ItemsSource="{Binding Modules}"
我可以看到设计时数据.知道我能做什么吗?
I can see the designtime data. Any idea what I could do?
推荐答案
这样做过(至少现在是这样):)
Been there done that (now at least) :)
这是我找到的解决方案.诀窍是覆盖 CollectionViewSource 设计时的源.我使用 d:DesignSource
属性来使用另一个静态资源设计时间:
This is the solution I've found. The trick is to override the source for the CollectionViewSource designtime. I use the d:DesignSource
property to use another static resource designtime:
<Window.Resources>
<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>
这篇关于绑定 CollectionViewSource 时,DesignTime 数据未显示在 Blend 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!