Comment : créer un BulletDecorator

Mise à jour : novembre 2007

Cet exemple montre comment le Bullet d'un contrôle BulletDecorator s'aligne avec différents types d'objets Child. Cet exemple présente également différents types d'objets Bullet.

Exemple

L'exemple suivant montre comment définir un contrôle BulletDecorator qui utilise une image comme Bullet et un objet de texte comme Child. Lorsqu'un objet de texte contient plusieurs lignes de texte, comme dans cet exemple, l'objet Bullet s'aligne avec la première ligne de texte.

Dim myBulletDecorator = New BulletDecorator()
Dim myImage = New Image()
Dim myBitmapImage = New BitmapImage()
myBitmapImage.BeginInit()
myBitmapImage.UriSource = _
   New Uri("pack://application:,,/images/apple.jpg")
myBitmapImage.EndInit()
myImage.Source = myBitmapImage
myImage.Width = 10
myBulletDecorator.Bullet = myImage
myBulletDecorator.Margin = New Thickness(0, 10, 0, 0)
myBulletDecorator.VerticalAlignment = VerticalAlignment.Center
myBulletDecorator.Background = Brushes.Yellow
Dim myTextBlock = New TextBlock()
myTextBlock.Text = "This BulletDecorator created by using code"
myTextBlock.TextWrapping = TextWrapping.Wrap
myTextBlock.HorizontalAlignment = HorizontalAlignment.Left
myTextBlock.Width = 100
myTextBlock.Foreground = Brushes.Purple
myBulletDecorator.Child = myTextBlock
BulletDecorator myBulletDecorator = new BulletDecorator();
Image myImage = new Image();
BitmapImage myBitmapImage = new BitmapImage();
myBitmapImage.BeginInit();
myBitmapImage.UriSource = new Uri(@"pack://application:,,/images/apple.jpg");
myBitmapImage.EndInit();
myImage.Source = myBitmapImage;
myImage.Width = 10;
myBulletDecorator.Bullet = myImage;
myBulletDecorator.Margin = new Thickness(0, 10, 0, 0);
myBulletDecorator.VerticalAlignment = VerticalAlignment.Center;
myBulletDecorator.Background = Brushes.Yellow;
TextBlock myTextBlock = new TextBlock();
myTextBlock.Text = "This BulletDecorator created by using code";
myTextBlock.TextWrapping = TextWrapping.Wrap;
myTextBlock.HorizontalAlignment = HorizontalAlignment.Left;
myTextBlock.Width = 100;
myTextBlock.Foreground = Brushes.Purple;
myBulletDecorator.Child = myTextBlock;
<BulletDecorator  Grid.Row="1" Grid.Column="0" Margin="0,5,0,0"
                  VerticalAlignment="Center" Background="Yellow">
  <BulletDecorator.Bullet>
    <Image Source="images\apple.jpg"/>
  </BulletDecorator.Bullet>
  <TextBlock
    Width="100" 
    TextWrapping="Wrap" 
    HorizontalAlignment="Left"
    Foreground ="Purple">
    A Simple BulletDecorator
  </TextBlock>
</BulletDecorator>

L'exemple suivant montre comment définir un contrôle BulletDecorator qui utilise une image comme Bullet et un objet de texte ayant une taille de police spécifiée comme Child. Étant donné que le Bullet est plus petit que les lettres spécifiées par la taille de police, l'objet Bullet se centre à côté du texte.

<BulletDecorator Margin="0,5,0,10" Grid.Column="0" Grid.Row="2"
  VerticalAlignment="Center">
  <BulletDecorator.Bullet>
    <Image Source="images\apple.jpg"/>
  </BulletDecorator.Bullet>
  <TextBlock Name="FontSizeExample"
    FontSize="12" Foreground="Green">FontSize = 12 </TextBlock>
</BulletDecorator>

L'exemple suivant montre comment définir un contrôle BulletDecorator qui utilise une image comme Bullet et un élément non-texte comme Child. Dans cet exemple, l'objet Bullet se centre à côté de l'élément non-texte.

<BulletDecorator Grid.Row="3" Grid.Column="0" Margin="0,5,0,0">
  <BulletDecorator.Bullet>
    <Image Source="images\apple.jpg"/>
  </BulletDecorator.Bullet>
  <Ellipse Height="75" Width="50" Fill="Purple" 
           HorizontalAlignment="Left" ></Ellipse>
</BulletDecorator>

L'exemple suivant présente trois types d'options Bullet pour un contrôle BulletDecorator.

<BulletDecorator Margin="0,5,0,0">
  <BulletDecorator.Bullet>
    <CheckBox/>
  </BulletDecorator.Bullet>
  <TextBlock
    Width="100" 
    TextWrapping="Wrap" 
    HorizontalAlignment="Left"
    Foreground = "Blue" 
    Margin="5,0,0,0">
    A BulletDecorator with a CheckBox Bullet.
  </TextBlock>
</BulletDecorator>
  <BulletDecorator Margin="0,5,0,0">
    <BulletDecorator.Bullet>
      <TextBox Width="30"/>
    </BulletDecorator.Bullet>
    <TextBlock
      Width="100" 
      TextWrapping="Wrap" 
      HorizontalAlignment="Left"
      Foreground ="Blue" 
      Margin="5,0,0,0">
      A BulletDecorator with a TextBox Bullet.
    </TextBlock>
  </BulletDecorator>
  <BulletDecorator Margin="0,5,0,0">
  <BulletDecorator.Bullet>
    <RadioButton/>
  </BulletDecorator.Bullet>
    <TextBlock
      Width="100" 
      TextWrapping="Wrap" 
      HorizontalAlignment="Left"
      Foreground ="Blue"
      Margin="5,0,0,0">
      A BulletDecorator with a RadioButton Bullet
    </TextBlock>
  </BulletDecorator>

Voir aussi

Référence

BulletDecorator