Wpf数据绑定......怎么样?

时间:2013-02-01 18:47:39

标签: c# wpf xaml data-binding

如何在Xaml中设置绑定

Xaml代码:

 ItemsSource="{Binding Path=compassLogCollection}"

.cs代码

 compassDataGrid.DataContext = LogSession.compassLogCollection;

compassLogCollection是静态 ObservableCollection<>

LogSession是一个单身人士(如果重要的话)

1 个答案:

答案 0 :(得分:1)

要回答您的第一个问题,您只需更改Xaml,如下所示:

 ItemSource = {Binding}

这告诉ItemSource直接绑定到DataContext

您的后续问题询问如何在Xaml中分配DataContext。为此,我建议你看一下这个问题 - How to instantiate DataContext object in XAML。如果这不起作用,那么你应该问另一个问题。