在WPF應用程序我有一個ListView
:WPF ListView的數據綁定到的ObservableCollection
<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
綁定聲明(在SecondWindow
ListView
)它與在MainWindow
的ObservableCollection
連接?