-2

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 MouseRightButtonUp event on debugging


MouseDoubleClick 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

Ali Asad
  • 1,235
  • 1
  • 18
  • 33
  • Please try to delete/disable all breakpoints in BreakPoint window, and then re-add just one, re-debug it again. If it still could not resolve the issue, please share a sample using one drive, and let us know the environment in your side, i.e the Visual Studio version and Widows OS version etc. So we could really repro this issue in our side. – Jack Zhai Jan 03 '18 at 09:37
  • Hi @JackZhai-MSFT the error is resolved after I updated the VS 2017. Thank you for replying. – Ali Asad Jan 03 '18 at 10:09
  • 1
    I’m glad to know that this issue has been resolved, you could share your solution as an answer, and then mark it. Have a nice day:) – Jack Zhai Jan 04 '18 at 02:50

3 Answers3

0

Try to restart VS after changing mode to "Debug". I did not implement this but I found something here.

Gaurang Dave
  • 3,956
  • 2
  • 15
  • 34
  • Thanks, but it doesn't work. Visual Studio is already running in the debug mode. Any other workaround that you may think out? – Ali Asad Jan 03 '18 at 05:47
  • Try to put that variable in watch window. Does it show "not in scope" or something. – Gaurang Dave Jan 03 '18 at 06:20
  • you can reset all VS settings as well and can try https://stackoverflow.com/questions/28730100/visual-studio-2015-debugging-cant-expand-local-variables/32143294 – Gaurang Dave Jan 03 '18 at 06:25
  • I copied the variable in the watch window, it shows an error 'Unable to evaluate the expression'. Also I tried to reset the VS-Setting and tried the solution that you have shared... But nothing works. – Ali Asad Jan 03 '18 at 07:19
  • Please check https://stackoverflow.com/questions/21166874/unable-to-evaluate-expression-whilst-debugging – Gaurang Dave Jan 03 '18 at 07:26
0

Have you tried to forcefully evaluate an expression? (select the expression and press Shift-F9)

Usually, if you try to evaluate something that VS for some reason can't, it will at least give you a proper error message to see the root cause of the issue.

I would bet that it may have something to do with code optimization. Make sure you run your application in Debug preset. Go to the project properties, and make sure you are generating full debug information and you don't have the "Optimize code" checkbox active.

TheXDS
  • 88
  • 9
0

I have able to resolve this by updating the VS 2017.

Ali Asad
  • 1,235
  • 1
  • 18
  • 33