用silverlight做了一个视频欣赏网页,一个网页中有三个视频,现在想单击全屏时,只让这一个视频全屏,就相当于页面中只有一个视频一样,这个怎么做?
用silverlight做了一个视频欣赏网页,一个网页中有三个视频,每个视频上都有播放,暂停,停止,全屏按钮,但是实现了当单击全屏时,是整个页面全屏,现在想单击全屏时,只让这一个视频全屏,就相当于页面中只有一个视频一样,这个怎么做?(页面中还有其他的控件元素)下面是三个视频的原来的代码。
<StackPanel Width="300" HorizontalAlignment="Center" Orientation="Horizontal">
<MediaElement x:Name="myPlayer1" Source="Video/Video1.wmv" AutoPlay="False" Margin="0,0,-2,-2" Width="300" Height="184"/>
<StackPanel x:Name="btn1" VerticalAlignment="Bottom" Orientation="Horizontal" HorizontalAlignment="Center" Margin="-300,0,0,0">
<Button x:Name="btnPlay" Content="播放" Height="25" Width="50" HorizontalAlignment="Left"/>
<Button x:Name="btnPause" Content="暂停" Height="25" Width="50" HorizontalAlignment="Left"/>
<Button x:Name="btnStop" Content="停止" Height="25" Width="50" HorizontalAlignment="Left"/>
<Button x:Name="btnFullScreen" Content="全屏" Height="25" Width="50" HorizontalAlignment="Left"/>
</StackPanel>
</StackPanel>
<StackPanel x:Name="Play2" Width="300" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Bottom" Height="184">
<MediaElement x:Name="myPlayer2" Source="Video/Video2.wmv" AutoPlay="False" Width="300" Height="184"/>
<StackPanel VerticalAlignment="Bottom" Orientation="Horizontal" HorizontalAlignment="Center" Margin="-300,0,0,0">
<Button Content="播放" Height="25" Width="50" HorizontalAlignment="Left"/>
<Button Content="暂停" Height="25" Width="50" HorizontalAlignment="Left"/>
<Button Content="停止" Height="25" Width="50" HorizontalAlignment="Left"/>
<Button Content="全屏" Height="25" Width="50" HorizontalAlignment="Left"/>
</StackPanel>
</StackPanel>
<StackPanel x:Name="Play3" Width="300" Orientation="Horizontal" VerticalAlignment="Bottom" HorizontalAlignment="Center" Height="184">
<MediaElement x:Name="myPlayer3" Source="Video/Video3.wmv" AutoPlay="False" Margin="0,0,-2,-2" Width="300" Height="184"/>
<StackPanel VerticalAlignment="Bottom" Orientation="Horizontal" HorizontalAlignment="Center" Margin="-300,0,0,0">
<Button Content="播放" Height="25" Width="50" HorizontalAlignment="Left"/>
<Button Content="暂停" Height="25" Width="50" HorizontalAlignment="Left"/>
<Button Content="停止" Height="25" Width="50" HorizontalAlignment="Left"/>
<Button Content="全屏" Height="25" Width="50" HorizontalAlignment="Left"/>
</StackPanel>
</StackPanel>
部分后台代码public partial class AllVideo : UserControl
{
public AllVideo()
{
InitializeComponent();
this.btnPlay.Click += new RoutedEventHandler(btnPlay_Click);
this.btnPause.Click += new RoutedEventHandler(btnPause_Click);
this.btnStop.Click += new RoutedEventHandler(btnStop_Click);
this.btnFullScreen.Click += new RoutedEventHandler(btnFullScreen_Click);
}
void btnFullScreen_Click(object sender, RoutedEventArgs e)
{
Application.Current.Host.Content.IsFullScreen = !Application.Current.Host.Content.IsFullScreen;
}
void btnStop_Click(object sender, RoutedEventArgs e)
{
myPlayer1.Stop();
}
void btnPause_Click(object sender, RoutedEventArgs e)
{
myPlayer1.Pause();
}
void btnPlay_Click(object sender, RoutedEventArgs e)
{
myPlayer1.Play();
}
}
[解决办法]
当点击单击对应的视频全屏得时候,首先获取用户屏幕分辨率,然后将对应的MediaElement设置为用户的屏幕像素大小,将其他的控件隐藏,最后设置全屏即可。
[解决办法]