Saisie¶
Champs texte, mots de passe, nombres, autocomplétion.
TextBox¶
v12
Watermark devient PlaceholderText, UseFloatingWatermark devient UseFloatingPlaceholder.
Libellé flottant¶
vide : le texte est dans le champ
E-mailrempli : il remonte au-dessus
Multiligne¶
Limiter et transformer¶
<TextBox MaxLength="10" PlaceholderText="10 caractères max" />
<TextBox CharacterCasing="Upper" PlaceholderText="Code pays" />
<TextBox IsReadOnly="True" Text="Lecture seule" />
<TextBox TextAlignment="Right" Text="1 250,00" />
Bouton d'effacement et préfixe¶
🔍✕gauche : 🔍 · droite : bouton ✕ (
clearButton)€droite : suffixe €
<TextBox Classes="clearButton" PlaceholderText="Rechercher">
<TextBox.InnerLeftContent>
<TextBlock Text="🔍" Margin="8,0,0,0" VerticalAlignment="Center" />
</TextBox.InnerLeftContent>
</TextBox>
<TextBox PlaceholderText="Montant">
<TextBox.InnerRightContent>
<TextBlock Text="€" Margin="0,0,10,0" VerticalAlignment="Center" Opacity="0.6" />
</TextBox.InnerRightContent>
</TextBox>
Réagir à la saisie¶
private void OnRecherche(object? sender, TextChangedEventArgs e)
=> Filtrer(Recherche.Text ?? "");
private void OnTouche(object? sender, KeyEventArgs e)
{
if (e.Key == Key.Enter) Lancer();
}
Manipuler le texte en code¶
Saisie.Focus();
Saisie.SelectAll();
Saisie.CaretIndex = Saisie.Text?.Length ?? 0;
Saisie.SelectedText; // texte sélectionné
Saisie.Clear();
Mot de passe¶
👁
revealPasswordButton ajoute l'œil pour afficher le mot de passe.
NumericUpDown¶
Un champ numérique avec boutons ▲▼ (et molette / flèches du clavier).
<NumericUpDown Value="1" Minimum="1" Maximum="99" Increment="1" FormatString="0" />
<NumericUpDown Value="19.90" Increment="0.5" FormatString="C2" />
<NumericUpDown Value="50" Minimum="0" Maximum="100" FormatString="0'%'"
ButtonSpinnerLocation="Left" />
Note
Value est de type decimal? : liez-le à une propriété decimal? ou decimal.
AutoCompleteBox¶
Un champ texte qui propose des suggestions pendant la frappe.
FilterMode="StartsWith"
<AutoCompleteBox x:Name="Ville" PlaceholderText="Ville" FilterMode="StartsWith"
MinimumPrefixLength="1" />
FilterMode |
Effet |
|---|---|
StartsWith |
commence par (insensible à la casse) |
Contains |
contient |
ContainsOrdinal |
contient, sensible à la casse |
Custom |
via ItemFilter |
Objets et filtre personnalisé¶
Pays.ItemsSource = listePays; // List<Pays>
Pays.ItemFilter = (texte, item) =>
item is Pays p && p.Nom.Contains(texte ?? "", StringComparison.OrdinalIgnoreCase);
Pays.ItemSelector = (texte, item) => ((Pays)item).Nom;
MaskedTextBox¶
Le masque impose le format : les caractères fixes sont déjà là, on ne remplit que les trous.
19/11/____
<MaskedTextBox Mask="00/00/0000" /> <!-- date -->
<MaskedTextBox Mask="00 00 00 00 00" /> <!-- téléphone FR -->
<MaskedTextBox Mask="LL-000-LL" /> <!-- plaque d'immatriculation -->
| Caractère | Accepte |
|---|---|
0 |
chiffre obligatoire |
9 |
chiffre optionnel |
L |
lettre obligatoire |
? |
lettre optionnelle |
A |
alphanumérique |
Formulaire complet¶
Inscription
Créer un compte
<StackPanel Spacing="12" MaxWidth="420" Margin="24">
<TextBlock Text="Créer un compte" FontSize="22" FontWeight="Bold" />
<TextBox PlaceholderText="Nom complet" UseFloatingPlaceholder="True" />
<TextBox PlaceholderText="E-mail" UseFloatingPlaceholder="True" />
<TextBox PlaceholderText="Mot de passe" UseFloatingPlaceholder="True"
PasswordChar="•" Classes="revealPasswordButton" />
<NumericUpDown Value="18" Minimum="18" Maximum="120" FormatString="0 'ans'" />
<CheckBox Content="J'accepte les conditions" />
<Button Content="Créer" Classes="accent" HorizontalAlignment="Stretch"
HorizontalContentAlignment="Center" />
</StackPanel>