bit*_*onk 15 wpf blend collectionviewsource
我有一个viewmodel的datatemplate,其中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>
Run Code Online (Sandbox Code Playgroud)
我还设置了UserControl,其中所有这些都被定义为提供设计时数据
d:DataContext="{x:Static vm:DesignTimeHelper.Equipment}">
Run Code Online (Sandbox Code Playgroud)
这基本上是一个静态属性,它给我一个EquipmentViewModel,它有一个ModuleViewModel(Equipment.Modules)列表.现在,只要我绑定到CollectionViewSource,设计时数据就不会出现在混合3中.当我直接绑定到ViewModel集合时
<ItemsControl ItemsSource="{Binding Modules}"
Run Code Online (Sandbox Code Playgroud)
我可以看到设计时数据.知道我能做什么吗?
去过那里(现在至少):)
这是我发现的解决方案.诀窍是覆盖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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2902 次 |
| 最近记录: |