如何在Xaml中设置绑定
Xaml代码:
ItemsSource="{Binding Path=compassLogCollection}"
.cs代码
compassDataGrid.DataContext = LogSession.compassLogCollection;
compassLogCollection是静态 ObservableCollection<>
和
LogSession
是一个单身人士(如果重要的话)
答案 0 :(得分:1)
要回答您的第一个问题,您只需更改Xaml
,如下所示:
ItemSource = {Binding}
这告诉ItemSource
直接绑定到DataContext
。
您的后续问题询问如何在Xaml中分配DataContext
。为此,我建议你看一下这个问题 - How to instantiate DataContext object in XAML。如果这不起作用,那么你应该问另一个问题。