私のクラスでは、ListBoxItem のダブルクリック イベントを作成しました。listBox のエントリをクリックすると、その特定のエントリのみが返されます。しかし、私の場合、単一のエントリをクリックしたにもかかわらず、すべてのエントリが返され、「InvalidCastException」が発生します。では、単一のエントリを取得するにはどうすればよいですか。
ダブルクリックイベントコードは次のとおりです。
private void ListBoxItem_DoubleClick(object sender, RoutedEventArgs e)
{
//Submit clicked Entry
Harvest_TimeSheetEntry entryToPost = (Harvest_TimeSheetEntry)sender;
if (!entryToPost.isSynced)
{
//Check if something is selected in selectedProjectItem For that item
if (entryToPost.ProjectNameBinding == "Select Project")
MessageBox.Show("Please Select a Project for the Entry");
else
Globals._globalController.harvestManager.postHarvestEntry(entryToPost);
}
else
{
//Already synced.. Make a noise or something
MessageBox.Show("Already Synced;TODO Play a Sound Instead");
}
}
In xml:
<ListBox x:Name="listBox1" ItemsSource="{Binding}" Margin="0,131,0,59" ItemTemplateSelector="{StaticResource templateSelector}" ListBoxItem.MouseDoubleClick="ListBoxItem_DoubleClick"/>