Auf Englisch lesen

Teilen über


VisualBrush.AutoLayoutContent Eigenschaft

Definition

Ruft einen Wert ab, der angibt, ob dieser VisualBrush das Layout für das eigene Visual ausführt, oder legt diesen fest.

C#
public bool AutoLayoutContent { get; set; }

Eigenschaftswert

Boolean

true, wenn dieser Pinsel das Layout für das eigene Visual ausführen soll, andernfalls false. Der Standardwert ist true.

Beispiele

Das folgende Beispiel zeigt die Auswirkungen der AutoLayoutContent Eigenschaft auf ein nicht übergeordnetes UIElementElement.

C#
StackPanel myStackPanel = new StackPanel();
myStackPanel.Margin = new Thickness(20, 0, 0, 0);
TextBlock myTextBlock = new TextBlock();
myTextBlock.Margin = new Thickness(0, 10, 0, 0);
myTextBlock.Text = "AutoLayoutContent: True";
myStackPanel.Children.Add(myTextBlock);

Rectangle myRectangle = new Rectangle();
myRectangle.Width = 100;
myRectangle.Height = 100;
myRectangle.Stroke = Brushes.Black;
myRectangle.StrokeThickness = 1;

// Create the Fill for the rectangle using a VisualBrush.
VisualBrush myVisualBrush = new VisualBrush();
myVisualBrush.AutoLayoutContent = true;

// This button is used as the visual for the VisualBrush.
Button myButton = new Button();
myButton.Content = "Hello, World";

myVisualBrush.Visual = myButton;

// Set the fill of the Rectangle to the Visual Brush.
myRectangle.Fill = myVisualBrush;

myStackPanel.Children.Add(myRectangle);

TextBlock myTextBlock2 = new TextBlock();
myTextBlock2.Margin = new Thickness(0, 10, 0, 0);
myTextBlock2.Text = "AutoLayoutContent: False";
myStackPanel.Children.Add(myTextBlock2);

Rectangle myRectangle2 = new Rectangle();
myRectangle2.Width = 100;
myRectangle2.Height = 100;
myRectangle2.Stroke = Brushes.Black;
myRectangle2.StrokeThickness = 1;

// Create the Fill for the rectangle using a VisualBrush.
VisualBrush myVisualBrush2 = new VisualBrush();
myVisualBrush2.AutoLayoutContent = false;

// This button is used as the visual for the VisualBrush.
Button myButton2 = new Button();
myButton2.Content = "Hello, World";
myButton2.Width = 100;
myButton2.Height = 100;

myVisualBrush2.Visual = myButton2;

// Set the fill of the Rectangle to the Visual Brush.
myRectangle2.Fill = myVisualBrush2;

myStackPanel.Children.Add(myRectangle2);
XAML
<StackPanel  Margin="20,0,0,0">
  <TextBlock Margin="0,10,0,0">AutoLayoutContent: True</TextBlock>
  <Rectangle 
    Width="100" 
    Height="100"
    Stroke="Black"
    StrokeThickness="1">
    <Rectangle.Fill>
      <VisualBrush AutoLayoutContent="True">
        <VisualBrush.Visual>
          <Button Content="Hello, World" />
        </VisualBrush.Visual>
      </VisualBrush>
    </Rectangle.Fill>
  </Rectangle>

  <TextBlock Margin="0,10,0,0">AutoLayoutContent: False</TextBlock>
  <Rectangle 
    Width="100" 
    Height="100"
    Stroke="Black"
    StrokeThickness="1">
    <Rectangle.Fill>
      <VisualBrush AutoLayoutContent="False">
        <VisualBrush.Visual>
          <Button Content="Hello, World" Width="100" Height="100" />
        </VisualBrush.Visual>
      </VisualBrush>
    </Rectangle.Fill>
  </Rectangle>
</StackPanel>

Die folgende Abbildung zeigt die Ausgabe des Beispiels:

AutoLayoutContent mit einem nicht-übergeordneten UIElement

Das nächste Beispiel zeigt die Auswirkungen der AutoLayoutContent Eigenschaft auf ein übergeordnetes UIElementElement.

C#
// Create a name scope for the page.
NameScope.SetNameScope(this, new NameScope());

StackPanel myStackPanel = new StackPanel();
myStackPanel.Margin = new Thickness(20, 0, 0, 0);
TextBlock myTextBlock = new TextBlock();
myTextBlock.Margin = new Thickness(0, 10, 0, 0);
myTextBlock.Text = "The UIElement";
myStackPanel.Children.Add(myTextBlock);

Button myButton = new Button();
myButton.Content = "Hello, World";
myButton.Width = 70;
this.RegisterName("MyButton", myButton);
myStackPanel.Children.Add(myButton);

TextBlock myTextBlock2 = new TextBlock();
myTextBlock2.Margin = new Thickness(0, 10, 0, 0);
myTextBlock2.Text = "AutoLayoutContent: True";
myStackPanel.Children.Add(myTextBlock2);

Rectangle myRectangle = new Rectangle();
myRectangle.Width = 100;
myRectangle.Height = 100;
myRectangle.Stroke = Brushes.Black;
myRectangle.StrokeThickness = 1;

// Create the Fill for the rectangle using a VisualBrush.
VisualBrush myVisualBrush = new VisualBrush();
myVisualBrush.AutoLayoutContent = true;
Binding buttonBinding = new Binding();
buttonBinding.ElementName = "MyButton";
BindingOperations.SetBinding(myVisualBrush, VisualBrush.VisualProperty, buttonBinding);

// Set the fill of the Rectangle to the Visual Brush.
myRectangle.Fill = myVisualBrush;

// Add the first rectangle.
myStackPanel.Children.Add(myRectangle);

TextBlock myTextBlock3 = new TextBlock();
myTextBlock3.Margin = new Thickness(0, 10, 0, 0);
myTextBlock3.Text = "AutoLayoutContent: False";
myStackPanel.Children.Add(myTextBlock3);

Rectangle myRectangle2 = new Rectangle();
myRectangle2.Width = 100;
myRectangle2.Height = 100;
myRectangle2.Stroke = Brushes.Black;
myRectangle2.StrokeThickness = 1;

// Create the Fill for the rectangle using a VisualBrush.
VisualBrush myVisualBrush2 = new VisualBrush();
myVisualBrush2.AutoLayoutContent = false;
Binding buttonBinding2 = new Binding();
buttonBinding2.ElementName = "MyButton";
BindingOperations.SetBinding(myVisualBrush2, VisualBrush.VisualProperty, buttonBinding2);

// Set the fill of the Rectangle to the Visual Brush.
myRectangle2.Fill = myVisualBrush2;

myStackPanel.Children.Add(myRectangle2);
XAML
<StackPanel Margin="20,0,0,0">

  <TextBlock Margin="0,10,0,0">The UIElement</TextBlock>
  <Button Name="MyButton" Content="Hello, World" />

  <TextBlock Margin="0,10,0,0">AutoLayoutContent: True</TextBlock>
  <Rectangle 
        Width="100" 
        Height="100"
        Stroke="Black"
        StrokeThickness="1">
    <Rectangle.Fill>
      <VisualBrush Visual="{Binding ElementName='MyButton'}" />
    </Rectangle.Fill>
  </Rectangle>

  <TextBlock Margin="0,10,0,0">AutoLayoutContent: False</TextBlock>
  <Rectangle 
    Width="100" 
    Height="100"
    Stroke="Black"
    StrokeThickness="1">
    <Rectangle.Fill>
      <VisualBrush Visual="{Binding ElementName='MyButton'}" 
                   AutoLayoutContent="False"/>
    </Rectangle.Fill>
  </Rectangle>
</StackPanel>

Die folgende Abbildung zeigt die Ausgabe des Beispiels:

AutoLayoutContent mit einem übergeordneten UIElement

Hinweise

Wenn diese Eigenschaft true nur wirksam UIElementwird, wenn es sich bei diesem Pinsel um ein nicht übergeordnetes Visual Element handelt.

Informationen zur Abhängigkeitseigenschaft

Bezeichnerfeld AutoLayoutContentProperty
Metadateneigenschaften auf true festgelegt Keine

Gilt für

Produkt Versionen
.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
Windows Desktop 3.0, 3.1, 5, 6, 7