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
で)をどのように変更する必要がありますか?SecondWindow
ObservableCollection
MainWindow