MaterialDesignInXAML / MaterialDesignInXAML/MaterialDesignInXamlToolkit
MaterialDesignToolToggleListBox with RadioButton behaviour
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 16.3k
- Forks
- 3.5k
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 8
Description
## 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

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

## 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];
}
}
}
}
```
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating MaterialDesignToolToggleListBox and ListBoxAssist, then inspect how toggle selection handles SelectionChanged for single-selection ListBox controls. Compare the proposed style and attached-property approaches; done means the selected item cannot be cleared, while SelectedValue binding remains valid.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100