Compartir a través de


Cómo: Crear un objeto BulletDecorator

Actualización: noviembre 2007

En este ejemplo se muestra cómo la propiedad Bullet de un control BulletDecorator se alinea con diferentes tipos de objetos Child. En este ejemplo se también muestra diferentes tipos de objetos Bullet.

Ejemplo

En el ejemplo siguiente se muestra cómo definir un control BulletDecorator que utilice una imagen como Bullet y un objeto de texto como Child. Cuando un objeto de texto contiene varias líneas de texto, como en este ejemplo, el objeto Bullet se alinea con la primera línea de texto.

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>

En el ejemplo siguiente se muestra cómo definir un control BulletDecorator que utiliza una imagen como Bullet y un objeto de texto que tiene un tamaño de fuente especificado como Child. Dado que Bullet es menor que las letras especificadas por el tamaño de fuente, el objeto Bullet se centra junto al texto.

<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>

En el ejemplo siguiente se muestra cómo definir un control BulletDecorator que utilice una imagen como Bullet y un elemento que no es de texto como Child. En este ejemplo, el objeto Bullet se centra junto al elemento que no es de texto.

<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>

En el ejemplo siguiente se muestran tres tipos de opciones Bullet para un control 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>

Vea también

Referencia

BulletDecorator