我似乎得到一个绑定的错误与一个数据网格上的SelectedItems集合绑定到我的ViewModel中的通用列表。WPF绑定错误Datagrid转换器SelectedItems
<DataGrid ItemsSource="{Binding Path=ListOfObjects}" SelectionMode="Extended" SelectionUnit="FullRow" SelectedItems="{Binding Path=ListOfSelectedObjects}" IsEnabled="{Binding Path=IsDoingNothing}">
这就是管道位...当我尝试从DataGrid中选择一个项目时,我得到的错误是在运行时抛出的。它似乎与默认值转换器将'SelectedItem'对象转换为我定义的类型有关。
我已经做了一些阅读,我想我需要某种价值转换器?但是我对这个有点新鲜,如果有人能够提供一些可以帮助我解决这个问题/管道/应用数据网格的例子,我会对它感到满意。
System.Windows.Data Error: 23 : Cannot convert 'Stored Data Backup' from type 'MyType' to type 'System.Collections.Generic.List`1[Entities.MyType]' for 'en-GB' culture with default conversions; consider using Converter property of Binding. NotSupportedException:'System.NotSupportedException: CollectionConverter cannot convert from Entities.MyType.
at System.ComponentModel.TypeConverter.GetConvertFromException(Object value)
at System.ComponentModel.TypeConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
at MS.Internal.Data.DefaultValueConverter.ConvertHelper(Object o, Type destinationType, DependencyObject targetElement, CultureInfo culture, Boolean isForward)'
System.Windows.Data Error: 7 : ConvertBack cannot convert value 'Stored Data Backup' (type 'MyType'). BindingExpression:Path=SelectedExcludedMyType; DataItem='MyTypeManagerViewModel' (HashCode=20097682); target element is 'DataGrid' (Name=''); target property is 'SelectedItem' (type 'Object') NotSupportedException:'System.NotSupportedException: CollectionConverter cannot convert from Dytecna.V001.Entities.MyType.
at MS.Internal.Data.DefaultValueConverter.ConvertHelper(Object o, Type destinationType, DependencyObject targetElement, CultureInfo culture, Boolean isForward)
at MS.Internal.Data.ObjectTargetConverter.ConvertBack(Object o, Type type, Object parameter, CultureInfo culture)
at System.Windows.Data.BindingExpression.ConvertBackHelper(IValueConverter converter, Object value, Type sourceType, Object parameter, CultureInfo culture)'
编辑:(编辑标题)我绑定到我想要的功能的datagrid的错误属性。我已经编辑了上面的XAML ...我想绑定到SelectedItems,这是复数,不SelectedItem,所以我可以selectr多行并将它们绑定到我的ViewModel中的列表...
我没有得到上面的绑定错误,我刚刚得到一个:
Error 1 'SelectedItems' property is read-only and cannot be set from markup.
那么我该如何绑定它呢?
谢谢blindmeis ...我刚才在代码中注意到了这个问题!我已经使用SelectedItem的绑定工作,我现在将功能扩展到SelectedItems ...这是我现在的问题。我编辑了这个问题并标记了你的答案,因为对于所有密集的目的你是对的,而且我错了! – tigerswithguitars
如果您不想使用Command解决方法,那么SelectedItems和Datagrid周围会有一些AttachedPropeties。例如:http://blogs.msdn.com/b/keithjones/archive/2009/10/02/multiple-selection-in-a-datagrid-should-be-bindable.aspx – blindmeis
Niffty代码...没有错误和它会调用gets ...所以我想它会很好。只需要安装人员即可工作。看起来好像有一段时间需要花费时间去理解这堂课。我想这比通过食谱做得更好。你说的是什么命令解决方法?我是一个渴望学习者! – tigerswithguitars