MaterialDesignInXAML / MaterialDesignInXAML/MaterialDesignInXamlToolkit

MaterialDesignToolToggleListBox with RadioButton behaviour

Open
#1,254 1 comment 8 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
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
![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];
}
}
}
}
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.