ShQuCollection
WPFアプリには、データバインディングを介してObservableCollectionに接続されているListViewがあります。
<ListView Name="ShSelList" ItemsSource="{Binding Source={StaticResource myDataSource},Path=ShQuCollection}" SelectionChanged="ShSelList_SelectionChanged">
<ListView.View>
<GridView>
<GridViewColumn Header="Code" DisplayMemberBinding="{Binding StrCode}"/>
<GridViewColumn Header="Date" DisplayMemberBinding="{Binding Date}"/>
<GridViewColumn Header="Time" DisplayMemberBinding="{Binding Time}"/>
</GridView>
</ListView.View>
</ListView>
ListView SelectionChangedイベントハンドラーの内部から、メソッドを呼び出して、ObservableCollectionの選択された行のフィールドの1つから取得する文字列パラメーターを渡す必要があります ShQuCollection
。
ListView SelectionChangedイベントハンドラー内からObservableCollectionを参照するにはどうすればよいですか?
private void ShSelList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
...?????
}
編集(追加):
私のObservableCollectionは別のウィンドウの分離コードファイルにあり、Window.Resources
宣言を使用してそれに到達します。
<Window.Resources>
<c:ShWindow x:Key="myDataSource"/>
</Window.Resources>
そして、ObservableCollectionは次のようになります。
ObservableCollection<ShsQu> _ShQuCollection =
new ObservableCollection<ShsQu>();
public ObservableCollection<ShsQu> ShQuCollection
{ get { return _ShQuCollection; } }
public class ShsQu
{
public string StrCode { get; set; }
public string Date { get; set; }
public string Time { get; set; }
}