Aller au contenu

Contrôles

Le catalogue des contrôles intégrés, par usage. Chaque page est une suite d'exemples.

Propriétés communes

Tous les contrôles héritent de ces propriétés :

<Button Content="Exemple"
        Width="160" MinHeight="32"
        Margin="8" Padding="12,6"
        HorizontalAlignment="Left"
        Background="#6D28D9" Foreground="White"
        BorderBrush="#5B21B6" BorderThickness="1" CornerRadius="6"
        FontSize="14" FontWeight="SemiBold"
        IsEnabled="True" IsVisible="True" Opacity="1"
        Cursor="Hand"
        ToolTip.Tip="Une infobulle"
        Classes="accent" />

Événements courants

<Border PointerPressed="OnPress" PointerEntered="OnEnter" PointerExited="OnExit"
        KeyDown="OnKeyDown" GotFocus="OnFocus" Focusable="True" />
private void OnPress(object? sender, PointerPressedEventArgs e)
{
    var point = e.GetCurrentPoint(sender as Control);
    if (point.Properties.IsRightButtonPressed) { /* clic droit */ }
    if (e.ClickCount == 2) { /* double-clic */ }
}

private void OnKeyDown(object? sender, KeyEventArgs e)
{
    if (e.Key == Key.Enter && e.KeyModifiers.HasFlag(KeyModifiers.Control))
    {
        Envoyer();
        e.Handled = true;   // stoppe la propagation
    }
}

// v12 : FocusChangedEventArgs remplace GotFocusEventArgs
private void OnFocus(object? sender, FocusChangedEventArgs e) { }

Lier deux contrôles sans ViewModel

#Nom désigne un élément nommé :

<StackPanel Spacing="8">
  <Slider x:Name="Taille" Minimum="10" Maximum="48" Value="16" />
  <TextBlock Text="Aperçu" FontSize="{Binding #Taille.Value}" />
  <CheckBox x:Name="Actif" Content="Activer" />
  <Button Content="Envoyer" IsEnabled="{Binding #Actif.IsChecked}" />
</StackPanel>