如何绑定 ObservableCollection在数据网格上?
我是大卫。我不知道在 WPF 应用程序的 XAML 中将集合绑定到数据网格。
下面是课程。
class TestSetting(): INotifyChanged
{
private a
public double A
{
get a;
set a = value;
Notify("A");
}
private b
public double B
{
get b;
set b = value;
Notify("B");
}
private c
public double C
{
get c;
set c = value;
Notify("C");
}
}
class TestCollect():ObservableCollection<T> ,INotifyListener
{
}
上面的代码是Psedo代码。
DataContext 有 7 个项目。所以网格将有 7 列。有人可以帮我提供一个示例或代码片段吗?
I'm David. I don`t know to bind collection to datagrid in XAML for a WPF application.
below are classes.
class TestSetting(): INotifyChanged
{
private a
public double A
{
get a;
set a = value;
Notify("A");
}
private b
public double B
{
get b;
set b = value;
Notify("B");
}
private c
public double C
{
get c;
set c = value;
Notify("C");
}
}
class TestCollect():ObservableCollection<T> ,INotifyListener
{
}
above code is Psedo code.
DataContext has 7 items. So the grid will have 7 columns. Could someone please help me with an example or a code snippet.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果数据上下文包含 TestCollection,则所需要做的就是将 ItemsSource 设置为
{Binding}
If the datacontext contains a TestCollection, all that is needed is Setting the ItemsSource to
{Binding}
我认为您需要的是这样的:
您的 viemodel :
您查看后面的代码
然后在您的视图中。这里重要的东西是' ItemsSource =“{Binding SourceList}”',它基本上意味着“我的列表框的源集合是我的数据上下文(它是一个Viewmodel对象)名为SourceList的集合”
I think that what you need is something like that :
Your viemodel :
You're view code behind
And then in your view. The important stuff here is ' ItemsSource="{Binding SourceList}" ' which basically means "the source collection of my listbox is the the collection of my datacontext (which is a Viewmodel object) named SourceList"
我是新手,但我会冒险回答:
第二。语句执行绑定。
I am a newbie, but I will venture my answer:
The 2nd. statement performs the binding.