gpt4 book ai didi

wpf - 与 CollectionViewSource 绑定(bind)时,DesignTime 数据未显示在 Blend 中

转载 作者:行者123 更新时间:2023-12-03 20:54:27 24 4
gpt4 key购买 nike

我有一个 View 模型的数据模板,其中项目控件绑定(bind)到 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}">

这基本上是一个静态属性,它为我提供了一个具有 ModuleViewModel (Equipment.Modules) 列表的 EquipmentViewModel。现在只要我绑定(bind)到 CollectionViewSource 设计时数据就不会显示在混合 3 中。当我直接绑定(bind)到 ViewModel 集合时
<ItemsControl ItemsSource="{Binding Modules}"

我可以看到设计时数据。知道我能做什么吗?

最佳答案

去过那里(至少现在):)
这是我找到的解决方案。诀窍是覆盖 CollectionViewSource 设计时的源。我使用 d:DesignSource使用另一个静态资源设计时的属性:

<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>

关于wpf - 与 CollectionViewSource 绑定(bind)时,DesignTime 数据未显示在 Blend 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1447962/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com