我正在WPF中开发一个应用程序。我创建了一个列表框,其中包含两个事件,即MouseDoubleClick
& MouseRightButtonUp
。当我运行程序并右键单击任何项目时,事件被触发但它不会显示调试模式中任何变量的值。但是,如果我双击列表框中的任何项目,我可以在调试时间中看到该事件中定义的变量值。我不确定为什么调试在一个事件中工作正常,在另一个事件中不能正常工作。
这里是xaml代码:
<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>
而且,MouseRightButtonUp
&amp; MouseDoubleClick
事件:
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;
}
感谢是否有人可以帮我确定此错误的原因。谢谢
答案 0 :(得分:0)
将模式更改为“Debug”后尝试重新启动VS.我没有实现这个,但我找到了here。
答案 1 :(得分:0)
您是否尝试过有力地评估表达式? (选择表达式并按Shift-F9)
通常情况下,如果您因某种原因尝试评估VS的某些内容,它至少会给您一个正确的错误消息,以查看问题的根本原因。
我敢打赌它可能与代码优化有关。确保在Debug预设中运行应用程序。转到项目属性,并确保您生成完整的调试信息,并且您没有&#34;优化代码&#34;复选框有效。
答案 2 :(得分:0)
我可以通过更新VS 2017来解决这个问题。