2

These days I wanna add a file select feature in my program.

I want to achieve select the file by drawing a rectangle with the mouse, just like the windows file explorer below: enter image description here

In my opinion, I should use a WrapPanel as a container, and then add CheckBoxs which rewrote ControlTemplate.

I have found some incomplete tutorial, just like:Drag selection box in WPF

Now I can draw the blue rectangle with my mouse by using the Adorner.

However, I don't know how to get to know which CheckBoxs are in the rectangle.

What's more, I don't know whether my opinion by using WrapPanel and CheckBox is a good choice for this.

Could you please give me a suggestion or a sample? Thank you.

Melon NG
  • 2,568
  • 6
  • 27
  • 52
  • Hi, is this what you might be looking for? https://stackoverflow.com/questions/1838163/click-and-drag-selection-box-in-wpf – ZarX Aug 31 '20 at 12:26
  • @ZarX It is something different. The way you provided is base on Canvas which can not arrange children items one by one with Row and Column while WrapPanel can. – Melon NG Aug 31 '20 at 13:38
  • @ZarX And also, File Explorer is selecting the items while you drawing the rectangle by mouse in real-time. It is an ordeal for performance. – Melon NG Aug 31 '20 at 13:41
  • Does this answer your question? [Click and drag selection box in WPF](https://stackoverflow.com/questions/1838163/click-and-drag-selection-box-in-wpf) – StayOnTarget Aug 31 '20 at 15:12
  • @UuDdLrLrSs The topic is the same as the comment of ZarX. However, as I said above, Canvas can't arrange children's items while WrapPanel can. – Melon NG Aug 31 '20 at 22:57
  • If its mainly the detection of which items the rectangle has contained - see https://stackoverflow.com/questions/14832037/wpf-hit-testing-a-rectangular-area maybe? – StayOnTarget Sep 01 '20 at 01:08
  • Incidentally it is possible to place items in the canvas wherever you want, but its definitely a lot more work. – StayOnTarget Sep 01 '20 at 01:08
  • @UuDdLrLrSs Let me try your ways. I have another idea by using System.Drawing.Rectangle.Contains to detect it while it is a winform method. – Melon NG Sep 01 '20 at 03:38

0 Answers0