I'm developing an application in WPF. I've created a list box which has two events i.e MouseDoubleClick
& MouseRightButtonUp
. When I run the program and right-click on any item, the event is triggered but it does not show the value of any variable in debugging mode. However, If I double-click on any item in the list box, I can see the variables values defined in that event in debug-time. I'm not sure why the debugging works fine in one event and doesn't work same in another event.
MouseRightButtonUp
event on debugging
MouseDoubleClick
event on debugging
here's the xaml code:
<ListBox ItemsSource="{Binding Items}" Name="detailList" Margin="5,5,0,0"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
MouseDoubleClick="detailList_MouseDoubleClick" MouseRightButtonUp="DetailList_OnMouseRightButtonUp">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal"></WrapPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate >
<DataTemplate>
<StackPanel Orientation="Vertical" Width="90" >
<Image Width="80" Source="{Binding Image}"/>
<TextBlock Width="60" Height="30" TextWrapping="Wrap" FontSize="11" Text="{Binding Name}" TextAlignment="Center"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
And, here's the code behind of MouseRightButtonUp
& MouseDoubleClick
events:
private void DetailList_OnMouseRightButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
//get the reference of current treeview
var items = (ListBox)sender;
//hold the reference of selected node
string fullPath = null;
// If selected item is a drive
if (items.SelectedItem is DirectoryItemViewModel)
{
fullPath = OnDriveDoubleClick((items.SelectedItem as DirectoryItemViewModel));
}
// If selected item is a folder
else if (items.SelectedItem is DirectoryItem)
{
fullPath = OnFolderDoubleClick((items.SelectedItem as DirectoryItem));
}
bool isFile = fullPath.Contains(".");
if (isFile)
{
this.m_Handler.FamilyPath = fullPath;
//On single click
this.m_Handler.SingleClicked = true;
m_ExEvent.Raise();
return;
}
}
private void detailList_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
//get the reference of current treeview
var items = (ListBox)sender;
//hold the reference of selected node
string fullPath = null;
// If selected item is a drive
if (items.SelectedItem is DirectoryItemViewModel)
{
fullPath = OnDriveDoubleClick((items.SelectedItem as DirectoryItemViewModel));
}
// If selected item is a folder
else if (items.SelectedItem is DirectoryItem)
{
fullPath = OnFolderDoubleClick((items.SelectedItem as DirectoryItem));
}
bool isFile = fullPath.Contains(".");
if (isFile)
{
this.m_Handler.FamilyPath = fullPath;
//On single click
// this.m_Handler.SingleClicked = true;
m_ExEvent.Raise();
return;
}
// Refresh the binding and view with the updated data in listbox
List<DirectoryItem> dir = DirectoryStructure.GetDirectoryContent(fullPath);
// Empty the old data from listbox
detailList.DataContext = null;
// bind new data to listbox
detailList.ItemsSource = dir;
}
Appreciate if anyone can help me identify the cause of this error. Thank you