MaterialDesignInXAML / MaterialDesignInXAML/MaterialDesignInXamlToolkit

MaterialDesignToolToggleListBox with RadioButton behaviour

Ouverte
#1,254 1 commentaire 8 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

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

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. 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

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.