首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >集合视图源使用问题

集合视图源使用问题
EN

Stack Overflow用户
提问于 2018-04-10 08:05:59
回答 1查看 0关注 0票数 0

我正在尝试对Collection ViewSource进行一种基本的使用,我肯定遗漏了一些东西,因为它不起作用。以下是我的XAML:

代码语言:txt
复制
<Window.Resources>
  <CollectionViewSource Source="{Binding loc:MainVM.Instance.MapItems}" x:Key="MapCV">
     <CollectionViewSource.GroupDescriptions>
        <PropertyGroupDescription PropertyName="SourceProject" />
     </CollectionViewSource.GroupDescriptions>
  </CollectionViewSource>
</Window.Resources>

代码语言:txt
复制
<ListBox ItemsSource="{StaticResource MapCV}" HorizontalContentAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Grid HorizontalAlignment="Stretch">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="2*"/>
                    <ColumnDefinition Width="2*"/>
                    <ColumnDefinition Width="50"/>
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Column="0" Text="{Binding SourceType, Converter={StaticResource WorkItemTypeToStringConverter}}"/>
                <ComboBox Grid.Column="1" SelectedItem="{Binding DestType}" ItemsSource="{Binding WorkItemTypesForCurrentDestProject, Source={x:Static loc:MainMediator.Instance}, diagnostics:PresentationTraceSources.TraceLevel=High}" DisplayMemberPath="Name" />
                <Button Grid.Column="2" Content="{Binding PercentMapped}"/>
            </Grid>
        </DataTemplate>                                        
    </ListBox.ItemTemplate>
</ListBox>

这编译得很好,但当我运行该应用程序时,我会得到以下错误:

代码语言:txt
复制
Cannot convert the value in attribute 'ItemsSource' to object of type 
'System.Collections.IEnumerable'. 'System.Windows.Data.CollectionViewSource' 
is not a valid value for property 'ItemsSource'.  Error at object 
'System.Windows.Controls.ListBox' in markup file 'WIAssistant;component/main.xaml

这是我附加到的收藏:

代码语言:txt
复制
// The mappings used to copy the values of the fields of one WorkItem to another.
public ObservableCollection<WorkItemTypeMapping> WorkItemTypeMappings
{
    get { return (ObservableCollection<WorkItemTypeMapping>)
          GetValue(WorkItemTypeMappingsProperty); }
    set { SetValue(WorkItemTypeMappingsProperty, value); }
}
public static readonly DependencyProperty WorkItemTypeMappingsProperty = 
    DependencyProperty.Register("WorkItemTypeMappings", 
    typeof(ObservableCollection<WorkItemTypeMapping>), typeof(MainMediator), 
    new UIPropertyMetadata(null));

我只想对对象进行简单的分组Project SourceProject我不想为了这个而冲出一片树景。

EN

回答 1

Stack Overflow用户

发布于 2018-04-10 17:36:58

这应该对你有用

代码语言:txt
复制
<ListBox ItemsSource="{Binding Source={StaticResource MapCV}}" ...
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100008047

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档