2011-09-25 50 views
1

在Winforms中,我使用Fill和Dock來實現這一點。如何在頂部填充視頻並在底部顯示標籤。 (填充和錨定)

我有一個「頁面」,我想播放視頻文件,並在底部顯示標籤。我希望網頁能夠伸展,並讓視頻拉伸並將標籤留在網頁的底部。

到目前爲止,我的嘗試總是導致播放視頻時覆蓋標籤。這怎麼解決?

(在StackPanel中其他控件省略)

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     x:Class="SDKSample.MediaElementExample" > 

    <DockPanel LastChildFill="True"> 
     <MediaElement Source="media\numbers.wmv" Name="myMediaElement" 
      LoadedBehavior="Manual" UnloadedBehavior="Stop" 
      MediaOpened="Element_MediaOpened" MediaEnded="Element_MediaEnded" 
      DockPanel.Dock="Top" Margin="50" /> 
     <StackPanel HorizontalAlignment="Center" Orientation="Horizontal" 
       Height="30" DockPanel.Dock="Bottom" Margin="50"> 
       <TextBlock Margin="5" VerticalAlignment="Center"> 
       Video Label 
       </TextBlock> 
     </StackPanel> 
    </DockPanel> 
</Page> 

溶液(感謝丹尼爾5月):

<Grid Height="Auto"> 
    <Grid.RowDefinitions> 
     <RowDefinition /> 
     <RowDefinition Height="30"/> 
    </Grid.RowDefinitions> 

    <MediaElement Source="media\numbers.wmv" Name="myMediaElement" LoadedBehavior="Manual" UnloadedBehavior="Stop" 
    MediaOpened="Element_MediaOpened" MediaEnded="Element_MediaEnded" /> 
    <StackPanel HorizontalAlignment="Center" Orientation="Horizontal" Height="30" Grid.Row="1"> 
     <Button Content="Button" Height="23" Name="button1" Width="75" Click="button1_Click" /> 
    </StackPanel> 
</Grid> 

回答

1

您可以使用Grid實現這一目標。

<Grid Height="300" Width="300"> 
    <Grid.RowDefinitions> 
     <RowDefinition /> 
     <RowDefinition Height="Auto"/> 
</Grid.RowDefinitions> 
    <MediaElement Source="media\numbers.wmv" 
      Name="myMediaElement" 
      LoadedBehavior="Manual" 
      UnloadedBehavior="Stop" 
      MediaOpened="Element_MediaOpened" 
      MediaEnded="Element_MediaEnded" /> 
    <TextBlock Margin="5" 
      Grid.Row="1" 
      VerticalAlignment="Center" 
      Text="Video Label" /> 
</Grid> 

第二RowDefinition使用Height屬性,迫使該行大小,以它的內容。之前的RowDefinition然後填充其餘的可用空間(在你的情況下,你的MediaElement)。