MaterialDesignInXAML / MaterialDesignInXAML/MaterialDesignInXamlToolkit
MaterialDesignToolToggleListBox with RadioButton behaviour
Personne n'a encore pris cette issue.
- Langage dominant
- C#
- Étoiles
- 16.3k
- Forks
- 3.5k
- Merge moyen
- 1 j 22 h
- PR mergées (30 j)
- 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];
}
}
}
}
```
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par localiser MaterialDesignToolToggleListBox et ListBoxAssist, puis examinez comment la sélection par bascule gère SelectionChanged pour les contrôles ListBox à sélection unique. Comparez les approches proposées avec style et attached property ; le travail est terminé lorsque l’élément sélectionné ne peut pas être désélectionné et que la liaison SelectedValue reste valide.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- csharp
- Domaine
- desktop
- Type d'issue
- Fonctionnalité
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100