在 WPF 应用程序中,我有一个ListView
:
<ListView Height="100" Width="434" x:Name="lvItems" ItemsSource="{Binding ElementName=MainWindow, Path=ShowQuCollection}" >
<ListView.View>
<GridView>
<GridViewColumn Header="Date" Width="100" DisplayMemberBinding="{Binding Date}"/>
<GridViewColumn Header="Time" Width="100" DisplayMemberBinding="{Binding Time}"/>
<GridViewColumn Header="Description" Width="200" DisplayMemberBinding="{Binding Description}"/>
</GridView>
</ListView.View>
ObservableCollection
通过数据绑定连接:
ObservableCollection<ShowsQu> _ShowQuCollection =
new ObservableCollection<ShowsQu>();
public ObservableCollection<ShowsQu> ShowQuCollection
{ get { return _ShowQuCollection; } }
public class ShowsQu
{
public string ShowCode { get; set; }
public DateTime Date { get; set; }
public TimeSpan Time { get; set; }
public string Description { get; set; }
}
这ObservableCollection
被放置在同一窗口的代码隐藏文件中,ListView
其中MainWindow
. 一切正常。
现在我将另一个添加ListView
到不同的窗口,在这种情况下数据绑定不起作用。这个 XAML 的数据绑定部分我没有改变:
ItemsSource="{Binding ElementName=MainWindow, Path=ShowQuCollection}
我应该如何更改此ListView
数据绑定声明 ( ListView
in SecondWindow
) 以使其与ObservableCollection
in连接MainWindow
?