我是WPF的初学者,在我创建的一个小程序中,有一个带有视频作为背景的窗口。
我使用了媒体元素,该视频上方还有其他内容。它可以在我单独进行的测试窗口中完美运行,但不在这里。我只是得到普通的背景。我浏览了media元素上的指南,但仍然找不到问题...
<Window x:Class="GlorifiedWallpaperApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:GlorifiedWallpaperApp"
mc:Ignorable="d"
ResizeMode="NoResize"
WindowState="Normal"
WindowStyle="None"
AllowsTransparency="True"
WindowStartupLocation="CenterScreen"
Title="LoginPage" Height="720" Width="1280">
<WindowChrome.WindowChrome>
<WindowChrome CaptionHeight="27"/>
</WindowChrome.WindowChrome>
<Grid FocusManager.FocusedElement="{Binding ElementName=passBox}">
<!--Definitions-->
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="100"/>
</Grid.RowDefinitions>
<!--BACKGROUND VIDEO-->
<MediaElement Source="/Resources/lensEffect.wmv"
Grid.Column="0" Grid.Row="0"
Grid.ColumnSpan="9" Grid.RowSpan="5"
x:Name="Lens_Effect"
MediaEnded="MediaElement_MediaEnded"
LoadedBehavior="Play" />
<Rectangle Grid.Column="0" Grid.Row="0"
Grid.ColumnSpan="9" Grid.RowSpan="5"
Fill="Black" Opacity="0">
</Rectangle>
<!--ENTER PIN TEXT-->
<TextBlock Foreground="White"
Grid.Column="3" Grid.Row="4"
Grid.ColumnSpan="3"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Margin="0,0,0,50"
FontSize="15" FontFamily="Courier New"
Opacity=".3">
<TextBlock.Text>
enter the pin above. i'm waiting...
</TextBlock.Text>
</TextBlock>
<!--EXIT BUTTON-->
<Button Grid.Column="0" Grid.Row="0"
Background="Transparent"
x:Name="Exit_Button"
BorderBrush="Transparent"
MaxHeight="40"
MaxWidth="40" Opacity=".5"
Click="Exit_Button_Click"
Style="{StaticResource buttonLogin}">
<Image Source="/Resources/LoginExitButton.png"/>
</Button>
<!--BGTextBox-->
<PasswordBox x:Name="passBox" Grid.Row="1" Grid.Column="0"
Grid.RowSpan="3" Grid.ColumnSpan="9"
Margin="0,0,0,0" MaxWidth="1000"
Background="Transparent" Foreground="#63ffdd"
BorderBrush="Transparent"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Top"
Opacity=".4" FontSize="400" MaxLength="6"
PasswordChar="•" Style="{StaticResource passwordFocusRemoval}">
<PasswordBox.InputBindings>
<KeyBinding Key="Return" Command="{Binding }" />
</PasswordBox.InputBindings>
</PasswordBox>
<!--MAIN LOGO-->
<Button Grid.Column="3" Grid.Row="1"
Grid.RowSpan="3" Grid.ColumnSpan="3"
Margin="0,0,0,50"
x:Name="Login_Logo" MaxHeight="170"
Style="{StaticResource buttonLogin}"
Click="Login_Logo_Click">
<Image Source="/Resources/LoginLogo.png"/>
</Button>
及其背后的代码:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
Collection myCollection = new Collection();
private void MediaElement_MediaEnded(object sender, RoutedEventArgs e)
{
Lens_Effect.Position = TimeSpan.FromMilliseconds(1);
}
private void keyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.OemComma)
MessageBox.Show("YAY!!!");
}
public void Exit_Button_Click(object sender, RoutedEventArgs e)
{
System.Diagnostics.Process.GetCurrentProcess().Kill();
}
private void Login_Logo_Click(object sender, RoutedEventArgs e)
{
if (passBox.Password == "key")
{
myCollection.Show();
this.Close();
}
}
}