Nota:
El acceso a esta página requiere autorización. Puede intentar iniciar sesión o cambiar directorios.
El acceso a esta página requiere autorización. Puede intentar cambiar los directorios.
Actualización: noviembre 2007
En el ejemplo siguiente se muestra cómo cambiar el valor de la propiedad Dock de DockPanel. En este ejemplo también se muestra la funcionalidad de los distintos valores de Dock.
Ejemplo
En el ejemplo se dibujan dos elementos Rectangle y se asigna Name a cada uno de ellos. Las dos filas de elementos Button representan los valores de enumeración Dock de cada Rectangle. Los botonesLightCoral representan el objeto Rectangle de color coral que se acopla inicialmente a la izquierda (Left); los botonesLightSkyBlue representan el objeto Rectangle de color azul claro que se acopla inicialmente a la derecha (Right). Al hacer clic en uno de estos botones, se inicia un controlador de eventos que cambia la posición de Dock. Además, el texto contenido en TextBlock cambia para mostrar la nueva dirección de acoplamiento de Rectangle.
Dispone del ejemplo completo en Ejemplo Dock Property.
<StackPanel Orientation="Horizontal" DockPanel.Dock="Top" Margin="0,0,0,10">
<Button Click="OnClick1" Background="LightCoral">Dock = "Left"</Button>
<Button Click="OnClick2" Background="LightCoral">Dock = "Right"</Button>
<Button Click="OnClick3" Background="LightCoral">Dock = "Top"</Button>
<Button Click="OnClick4" Background="LightCoral">Dock = "Bottom"</Button>
</StackPanel>
<TextBlock DockPanel.Dock="Top" Name="Txt2">The Dock property of the LightSkyBlue Rectangle is set to Right</TextBlock>
<StackPanel Orientation="Horizontal" DockPanel.Dock="Top" Margin="0,0,0,10">
<Button Click="OnClick5" Background="LightSkyBlue" Foreground="White">Dock = "Left"</Button>
<Button Click="OnClick6" Background="LightSkyBlue" Foreground="White">Dock = "Right"</Button>
<Button Click="OnClick7" Background="LightSkyBlue" Foreground="White">Dock = "Top"</Button>
<Button Click="OnClick8" Background="LightSkyBlue" Foreground="White">Dock = "Bottom"</Button>
</StackPanel>
<TextBlock DockPanel.Dock="Top" Name="Txt3">The LastChildFill property is set to True (default).</TextBlock>
<StackPanel Orientation="Horizontal" DockPanel.Dock="Top" Margin="0,0,0,10">
<Button Click="OnClick9" Background="White">LastChildDock="True"</Button>
<Button Click="OnClick10" Background="White">LastChildDock="False"</Button>
</StackPanel>
<Border Background="LightGoldenRodYellow" BorderBrush="Black" BorderThickness="1">
<DockPanel Name="myDP">
<Rectangle Name="rect1" MinWidth="200" MinHeight="200" Stroke="Black" Fill="LightCoral" />
<Rectangle Name="rect2" MinWidth="200" MinHeight="200" Stroke="Black" Fill="LightSkyBlue" />
</DockPanel>
</Border>
Los eventos que se definen en el archivo de Lenguaje de marcado de aplicaciones extensible (XAML) anterior se controlan en un archivo de código subyacente.
Private Sub OnClick1(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs)
System.Windows.Controls.DockPanel.SetDock(rect1, System.Windows.Controls.Dock.Left)
Txt1.Text = "The Dock property of the LightCoral Rectangle is set to Left"
End Sub
private void OnClick1(object sender, RoutedEventArgs e)
{
DockPanel.SetDock(rect1, Dock.Left);
Txt1.Text = "The Dock Property of the LightCoral Rectangle is set to Left";
}
Vea también
Conceptos
Información general sobre elementos Panel