1

下面是我的 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 组合。任何人都可以帮忙吗?问候,赫曼特

4

1 回答 1

1

明白了.. 需要使用媒体元素的 Stretch 属性。

<MediaElement  Name="me" HorizontalAlignment="Stretch" LoadedBehavior="Manual"
                   VerticalAlignment="Stretch" Stretch="Fill"/>
于 2013-05-20T09:47:03.403 回答