问题标签 [itemssource]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
482 浏览

c# - 选择正确的 ItemsSource 容器

我有一个我编写的 UserControl 来显示自定义对象的一些属性。这些对象有多个实例,因此我有它们的 ObservableCollection,因此我可以将它们设置为绑定到 ListView 的 ItemsSource。现在,我可以在我的 ListView 中为我的类的每个实例显示这个 UserControl 的实例。

问题是我真的不想要 ListView 的行为。我不希望用户能够选择整个 UserControl。事实上,用户应该能够选择 UserControl 中的各个元素。

我想过只使用 StackPanel 将这些 UserControls 放入,但它没有 ItemesSource 属性。有没有一种简单的方法可以做到这一点?

0 投票
1 回答
2838 浏览

wpf - WPF ComboBox 绑定到枚举

我有一个组合框,它使用 ObjectDataProvider 将 ItemsSource 绑定到枚举,并且其 SelectedItem 属性绑定到业务对象的属性。出于某种原因,它首先绑定 SelectedItem,然后绑定 ItemsSource,因此覆盖了我对 businessobject 属性的默认设置。任何想法为什么和可能的修复?提前致谢。

XAML:

0 投票
2 回答
195 浏览

c# - WPF 绑定噩梦

所以我有一堂课

ItemsSource现在我有一个我希望绑定到myObject的网格控件MyObjectCollection

怎么做?

0 投票
1 回答
4116 浏览

silverlight - 如何在 silverlight 中使用集合类作为静态资源

我有一个Customer用 2 个属性命名的简单类。 然后我创建了一个集合类,命名只有一个名为 Customers 的公共属性
public Name {get;set;}
public LastName {get;set}

CustomerList

现在我想将这个类用作 XAML 中的静态资源。

然后在 ListBox 中使用它

如果我在代码中设置 ItemsSource,在实例化类之后,一切正常。如果我尝试从 XAML 和静态资源设置它什么都不会发生。即使我使用{Binding Path=Customer.Name}or 也不行{Binding Path=Name}

显然我错过了一些东西......

0 投票
1 回答
1708 浏览

wpf - 自定义集合在编辑时崩溃 DataGrid

我目前正在尝试将 DataGrid.ItemsSource 绑定到自定义 RowCollection,该 RowCollection 实现了 IList 和 INotifyCollectionChanged:

Public Class RowCollection(of T)
Implements IList(Of T)
Implements INotifyCollectionChanged
Private _List As New List(Of T)
...

(对不起 VB 代码,我很快就会把我所有的代码翻译成 C#。)

请注意,该类不是从任何现有的 CLR 集合派生的。我创建了自己的类,因为我需要重写 GetItemAt,以实现记录分页。Collection 在内部从它自己的私有 List 中添加和删除对象_List

现在,我可以查看 DataGrid 中的项目,但只要双击要编辑的单元格,我就会收到InvalidOperationException:'EditItems' 不可用。.

我的问题是,为了使我的集合与 DataGrid 完全兼容,我应该实现哪些其他接口?

0 投票
2 回答
7065 浏览

wpf - WPF DataGrid ItemsSource 绑定问题

我在 WPF 应用程序中有一个 DataGrid,它将自身绑定到对象的 ObservableCollection,一切正常。现在,如果我在运行时修改数据网格中的单元格并删除内容,请将单元格留空。observableCollection 对应的值不会被修改,会是旧值。但是当我退出包含数据网格的窗口并重新启动窗口时,它会抛出 XamlParseException,说:“Set Property 'System.Windows.Controls.ItemsControl.ItemsSource' throw an exception”

只要我关闭窗口,数据网格中没有单元格为空,它就不会抛出异常。我还在 Window 执行 InitializeComponent Line 之前检查了 Collection,它看起来非常好,所有对象都有正确的值,没有空值或空值。我无法弄清楚为什么它会抛出这个异常。有任何想法吗?提前致谢。

XAML:

0 投票
1 回答
8007 浏览

wpf - WPF ListBox ItemsSource with DataTemplate

I have a ListBox with an ItemsSource pointing to a static variable, and a DataTemplate for the ListBox's ItemTemplate that should be displaying the Description property of the variable the ItemsSource points to

I can put a break point on my application and view the ListBox. The ItemsSource does point to the variable I want and it looks like the ListBox is trying to display all the values because I can click and scroll down the it. However, no text is getting displayed so you can't actually tell what you're clicking. Also, while the break point is on, it says that the list box contains 0 items, maybe it should because I'm binding it, not sure. Any suggestions?

0 投票
1 回答
191 浏览

c# - 选择行时出现 DataGrid 错误

下面的问题解释起来并不简单。我有一个包含 DataGrid 的窗口和窗口的 ViewModel。window.DataContext 包含 ViewModel。DataGrid.ItemSource 包含一个 ObservableCollection。DataGrid 的 RowStyle 的 IsSelected 属性绑定到 PointData 中的 IsSelected 属性。

当我关闭窗口并打开一个新窗口时......并用旧的 ViewModel 数据填充它。选择“旧”行会引发一个烦人的异常,上面写着:“集合已修改;枚举操作可能无法执行”

如果有人有解决这种情况的想法,我会非常感谢您的帮助。谢谢

0 投票
4 回答
228 浏览

silverlight - Silverlight 列表框问题

我正在使用listBox.ItemsSource = e.Result.Persons,这是一个人的集合。当我希望它显示每个人对象的名字时,列表框会显示实际的对象名称。我怎样才能做到这一点?

0 投票
5 回答
416 浏览

silverlight - EmptyListBox 控件未收到通知 ItemsSouce 已更改 (silverlight / wp7)

如果列表框中没有项目,尝试可能会显示“无数据”。由于我在 wp7 上并使用 silverlight,因此我无法使用 DataTriggers,因此我创建了一个控件以使其在整个应用程序中的行为保持一致。但是我如果你为 set 方法设置断点 - 它根本不会被调用!

控制类

这是 xml

代码隐藏:

客户端模型类:

显示问题的解决方案 .ZIP 的链接