MaterialDesignInXAML / MaterialDesignInXAML/MaterialDesignInXamlToolkit

MaterialDesignToolToggleListBox with RadioButton behaviour

Đang mở
#1,254 1 bình luận 8 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

enhancement
Ngôn ngữ chính
C#
Star
16.3k
Fork
3.5k
Merge trung bình
1 ngày 22 giờ
Pull request đã merge (30 ngày)
8

Mô tả

## Background
I'm using the `MaterialDesignToolToggleListBox` for selecting one of up to three possible modes that can be available to the user. The current implementation of `MaterialDesignToolToggleListBox` will allow the user to unselect items in the list box which leaves us with no item selected.

### Current Behaviour
![CurrentBehaviour](https://user-images.githubusercontent.com/1139118/57905664-88054980-7877-11e9-8b20-9778c708aecc.gif)

Since i'm binding the `SelectedValue` of the `ListBox` I will get a binding/validation error since the `SelectedItem` will be `null` when the user unselect the item.

### Expected Behaviour
![ExpectedBehaviour](https://user-images.githubusercontent.com/1139118/57905684-9489a200-7877-11e9-846d-e861ab0c1fab.gif)

## Solutions
I would like to set a property on `ListBoxAssist` or use a new style to get a `RadioButton` behaviour on `MaterialDesignToolToggleListBox`.

1. Create a new style `MaterialDesignToolRadioButtonListBox` which uses `RadioButton` to achieve the desired result. (I have not tried this)
2. Use an attached property to hook into the `SelectionChanged` event and prevent unselect. Possible name could be `PreventUnselect`

*Pseudo code for option 2*

```
private void SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if(sender is ListBox listBox)
{
if (ListBoxAssist.GetIsToggle(listBox) &&
listBox.SelectionMode == SelectionMode.Single)
{
if (e.AddedItems.Count == 0 && e.RemovedItems.Count == 1)
{
listBox.SelectedItem = e.RemovedItems[0];
}
}
}
}
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách xác định MaterialDesignToolToggleListBox và ListBoxAssist, sau đó kiểm tra cách lựa chọn chuyển đổi xử lý SelectionChanged đối với các control ListBox chỉ cho phép chọn một mục. So sánh các cách tiếp cận được đề xuất bằng style và attached property; công việc được hoàn tất khi không thể xóa mục đã chọn và binding SelectedValue vẫn hợp lệ.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
csharp
Lĩnh vực
desktop
Loại issue
Tính năng
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.