MediaElement布局占据整个空间

时间:2013-05-20 09:28:18

标签: wpf layout

下面是我的xaml代码,其中我在网格中托管了Mediaelement和3按钮。

<Grid ShowGridLines="True">
  <Grid.Background>
    <LinearGradientBrush EndPoint="0.5,1"
                         StartPoint="0.5,0">
      <GradientStop Color="Black"
                    Offset="0" />
      <GradientStop Color="#FF4F87F7"
                    Offset="1" />
    </LinearGradientBrush>
  </Grid.Background>
  <Grid.RowDefinitions>
    <RowDefinition Height="7*" />
    <RowDefinition Height="35" />
  </Grid.RowDefinitions>
  <Grid.ColumnDefinitions>
    <ColumnDefinition Width="10*" />
    <ColumnDefinition Width="Auto" />
    <ColumnDefinition Width="5*" />
    <ColumnDefinition Width="1*" />
  </Grid.ColumnDefinitions>
  <Border Grid.ColumnSpan="4"
          HorizontalAlignment="Stretch"
          Grid.Row="1"
          BorderThickness="2"
          CornerRadius="5"
          BorderBrush="Black">

    <StackPanel Orientation="Horizontal"
                HorizontalAlignment="Center">
      <Button Width="100"
              Content="Previous"
              Style="{DynamicResource buttonMargin}" />
      <Button Width="100"
              Content="Play"
              Style="{DynamicResource buttonMargin}"
              Click="Button_Click" />
      <Button Width="100"
              Content="Next"
              Style="{DynamicResource buttonMargin}" />
      <ToggleButton Style="{DynamicResource toggleButtonMargin}">Full Screen</ToggleButton>
    </StackPanel>

  </Border>
  <MediaElement  Name="me"
                 HorizontalAlignment="Stretch"
                 LoadedBehavior="Manual"
                 VerticalAlignment="Top"
                 Grid.IsSharedSizeScope="True" />
  <GridSplitter Grid.Column="1"
                Width="3"
                HorizontalAlignment="Center" />
  <WebBrowser Name="webBrowserScript"
              Grid.Column="2" />
</Grid>

问题:我的目标是在第0行和第0列渲染MediaElement,它应该占据整个空间。但是,MediaElement并没有完全拉伸,也没有占据整个空间。我尝试了Horizo​​ntalAlignment和VerticalAlignment的所有可能组合。有人可以帮忙吗? 问候, 与Hemant

1 个答案:

答案 0 :(得分:1)

得到了.. 需要使用media元素的Stretch属性。

<MediaElement  Name="me" HorizontalAlignment="Stretch" LoadedBehavior="Manual"
                   VerticalAlignment="Stretch" Stretch="Fill"/>