¿Por qué DockPanel.Dock = & # 8220; Bottom & # 8221; ¿Poner elemento en la parte superior?

StackOverflow https://stackoverflow.com/questions/1005670

  •  05-07-2019
  •  | 
  •  

Pregunta

El siguiente código coloca los dos elementos de texto en la parte superior, a pesar de que el segundo está marcado como " Parte inferior " ;. El color de fondo va hasta el fondo, por lo que el DockPanel parece extenderse hasta el fondo.

¿Qué es lo que no entiendo sobre DockPanel?

<Window x:Class="TestIndexer934.Views.MainView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:c="clr-namespace:TestIndexer934.Commands"
    Title="Main Window" Height="400" Width="800">
    <DockPanel HorizontalAlignment="Left" Background="Beige">
        <TextBlock DockPanel.Dock="Top" Text="Testing top"/>
        <TextBlock DockPanel.Dock="Bottom" Text="Testing bottom"/>
    </DockPanel>
</Window>
¿Fue útil?

Solución

Por predeterminado el último elemento de DockPanel's llenará el área de contenido restante disponible.

Si configura LastChildFill = " False " en el DockPanel, verá el comportamiento que espera. También puede establecer VerticalAlignment = " Parte inferior " en el TextBlock.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top