如何修复ListView选择更改?

时间:2022-06-02 22:57:38

I have a ListView whose children are the grdis that contain an image, and four buttons. They are all populated dynamically. Here is the code for selection change event for the ListView:

我有一个列表视图,它的子元素是包含图像的grdis,以及四个按钮。它们都是动态填充的。下面是列表视图选择更改事件的代码:

 private void Thumbnails_SelectionChanged(object sender, SelectionChangedEventArgs e) //display large png on click of thumbnail and slide notes
        {

            item = Thumbnails.SelectedIndex + 1; //get original index for each element in ListView


            if (LargePic.Children.Count > 0)
            {
                LargePic.Children.RemoveAt(LargePic.Children.Count - 1); //clear first item in StackPanel
            }


            LargePic.Children.Add(image_array[item - 1]); //show large png of selected ppt as first item in StackPanel



            SlideNotes.Text = slide_notes[item - 1]; //show slide notes in a box below large preview
            //GetNotes(PowerPoint_App, presentation)[item - 1];

            finalize_import.IsEnabled = true; //enable button for next screen

            //selection
            all_hide_buttons[item - 1].Click += Hide_Buton_Click;
            all_show_buttons[item - 1].Click += Show_Buton_Click;
            hide_fade_in_animations[item - 1].Click += Hide_Fade_In_Animations_Click;
            show_fade_in_animations[item - 1].Click += Show_Fade_In_Animations_Click;



        } 

So as you can see, buttons can be clicked only if specific child (item) is selected on the list and further perform some action based on this item number. My problem is that the SelectionChanged gets executed only if I click on the image which is the part of the child grid in the list, so only then these buttons become clickable. I want it to execute if I click directly on the button, so the button actually clicks immediately if I click it, without the need to click the image first. Is this possible and how?

因此,如您所见,只有在列表中选择了特定的子(项目)并基于这个项目号进一步执行一些操作时,才能单击按钮。我的问题是,只有当我单击列表中子网格的一部分图像时,才会执行SelectionChanged,因此这些按钮才会成为可单击的。我想要它执行,如果我直接点击按钮,所以按钮实际上点击,如果我点击它,不需要先点击图像。这是可能的吗?

1 个解决方案

#1


0  

This solved my problem. Not exactly what I wanted, but it does the job,

这解决了我的问题。不完全是我想要的,但它确实起了作用,

Mouseover to select item in listbox in WPF

鼠标移到在WPF的列表框中选择项

So, then main thing in my problem was that I need to click listview item first in order to be able to click the button within the item. In the link that I have included you can see that if we add proper event to the listivew, then as we hover an item, selection changed gets triggered automatically, same as if we clicked it, which saves one click and gets the desired button enabled as soon as the mouse is over the item. It is a little bit of cheating, but the main thing here is that the mouse pointer ca not make to this button within listview item before actually touching a pixel from the item.

我的问题中最主要的一点是我需要先点击listview项才能点击项内的按钮。链接我包括你可以看到,如果我们listivew添加适当的事件,当我们徘徊一个项目,选择更改会自动触发,如果我们点击它,一样可以节省一个单击并获得所需的按钮启用项目只要鼠标。这有点作弊,但这里的主要问题是鼠标指针在实际触摸到列表视图项中的一个像素之前不会指向这个按钮。

#1


0  

This solved my problem. Not exactly what I wanted, but it does the job,

这解决了我的问题。不完全是我想要的,但它确实起了作用,

Mouseover to select item in listbox in WPF

鼠标移到在WPF的列表框中选择项

So, then main thing in my problem was that I need to click listview item first in order to be able to click the button within the item. In the link that I have included you can see that if we add proper event to the listivew, then as we hover an item, selection changed gets triggered automatically, same as if we clicked it, which saves one click and gets the desired button enabled as soon as the mouse is over the item. It is a little bit of cheating, but the main thing here is that the mouse pointer ca not make to this button within listview item before actually touching a pixel from the item.

我的问题中最主要的一点是我需要先点击listview项才能点击项内的按钮。链接我包括你可以看到,如果我们listivew添加适当的事件,当我们徘徊一个项目,选择更改会自动触发,如果我们点击它,一样可以节省一个单击并获得所需的按钮启用项目只要鼠标。这有点作弊,但这里的主要问题是鼠标指针在实际触摸到列表视图项中的一个像素之前不会指向这个按钮。