Прочетете на английски Редактиране

Споделяне чрез


BulletDecorator.Background Property

Definition

Gets or sets the background color for a BulletDecorator control.

C#
public System.Windows.Media.Brush Background { get; set; }

Property Value

The background color for the Bullet and Child of a BulletDecorator. The default is null.

Examples

The following examples show how to set the Background property on a BulletDecorator control.

C#
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;
XAML
<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>

Remarks

The Background property defines the Brush to use to fill the area within the BulletDecorator. For some parent layout elements, the area that is defined for the BulletDecorator may extend beyond its Bullet and Child content. For example, if the BulletDecorator is the single child of a cell in a Grid control, the Background property applies to the whole cell. This occurs because the content in a Grid cell is stretched in all directions to fill the cell, by default. However, if you set the VerticalAlignment property to Center for the BulletDecorator, the Background property only affects the actual content area of the BulletDecorator. Alternatively, you can enclose the BulletDecorator in a Panel element.

Dependency Property Information

Item Value
Identifier field BackgroundProperty
Metadata properties set to true AffectsRender, SubPropertiesDoNotAffectRender

Applies to

Продукт Версии
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also