How to make Check All in Listbox?

1 Answer 68 Views
ListBox Styling
Psyduck
Top achievements
Rank 4
Bronze
Bronze
Bronze
Psyduck asked on 02 Aug 2021, 01:19 AM

Hello.

I would like to ask about the Check All function in using listbox.
I usually leave Check All aside.
But when I looked at the sample of ASP.NET (Teleik), I saw that they were tied together.

Is this even possible in WPF? What conditions are required for that?

 

Thanks.

1 Answer, 1 is accepted

Sort by
1
Dilyan Traykov
Telerik team
answered on 03 Aug 2021, 09:39 AM

Hello Psyduck,

Thank you for the provided image.

There are two possible approaches for achieving the desired result - to edit the control template of the RadListBox control or to create an attached behavior in which you can modify the composing elements and add the CheckBox programmatically.

Please note that in both cases, the required modifications may be different based on the theme you're using.

For your convenience, I've prepared a small sample project which demonstrates how to achieve this via an attached behavior for the Office Black theme. If you're using another theme and this approach does not work for you, please let me know which theme(s) you use and I will gladly try to update the solution to work for your particular scenario.

Regards,
Dilyan Traykov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Psyduck
Top achievements
Rank 4
Bronze
Bronze
Bronze
commented on 04 Aug 2021, 12:29 AM | edited

Hello.

 

The sample you provided is exactly what I want.

For themes, I use Fluent, and I have confirmed that there is no problem with it.

However, there is a bit of a problem with the IsSelected process.

I made a gif, but I can't attach it, so I upload 1-6 image files(png).

If you click the corner of the center of the item after clicking the multi-item, selected is initialized to 1 and disappears.

However, if the IsChecked property is created and used, it is not checked, but the SelectedItem becomes Single and one is selected.

How should I do this?

 

+  The ScrollBar is also missing.

I checked that the ScrollViewer exists in the border and the bar setting is set to auto.

 

Thanks.

Dilyan Traykov
Telerik team
commented on 04 Aug 2021, 12:38 PM

Thank you for the provided images.
The reason for the undesired behavior with the selection is that the CheckBox does not stretch to the whole RadListBox item. To achieve this, you need to remove the default padding for the Items and transfer it to the CheckBox.
As for the missing scrollbar, this is because the StackPanel has an infinite height. Please excuse me for overlooking this. This issue can be resolved by replacing the StackPanel with a Grid panel.
For your convenience, I've gone ahead and applied both these modifications to the attached project. Please have a look and let me know if it provides the desired result.
Psyduck
Top achievements
Rank 4
Bronze
Bronze
Bronze
commented on 05 Aug 2021, 12:23 AM

Thanks this works fine!

 I still have the same problem even after setting the padding of the listboxitem to 0.
(The occurrence range is narrowed)

So I set the checkbox margin  = "0 -1" .
Tags
ListBox Styling
Asked by
Psyduck
Top achievements
Rank 4
Bronze
Bronze
Bronze
Answers by
Dilyan Traykov
Telerik team
Share this question
or