如何:创建 BulletDecorator
此示例演示如何将 BulletDecorator 控件的 Bullet 与不同类型的 Child 对象对齐。 此示例还演示不同类型的 Bullet 对象。
示例
下面的示例演示如何定义将图像用作 Bullet 并将文本对象用作 Child 的 BulletDecorator 控件。 当文本对象包含多行文本时,如本示例中的文本,Bullet 对象将与第一行文本对齐。
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>
下面的示例演示如何定义将图像用作 Bullet 并将指定字体大小的文本对象用作 Child 的 BulletDecorator 控件。 因为 Bullet 比指定字号的字母小,所以 Bullet 对象会将自己放置在文本旁边并居中。
<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>
下面的示例演示如何定义将图像用作 Bullet 并将非文本元素用作 Child 的 BulletDecorator 控件。 在此示例中,Bullet 对象会将自己放置在非文本元素的旁边并居中。
<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>
下面的示例演示用于 BulletDecorator 控件的三种类型的 Bullet 选项。
<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>