我创建了一个 C# WPF 应用程序。因为我有有限的 UI 组件(标签、MediaElement、图像源(4))。我正在使用最大化窗口加载我的应用程序。当我启动我的 exe 时,黑屏会显示一秒钟,然后会出现实际的 UI。
我设置了一个属性,即 AllowsTranparency = True。它解决了上述问题,但要花费一个新的成本,即,如果将此属性设置为 true,则在 MediaElement 中播放的视频会滞后很多。
所以,这个解决方案被排除了。
应用程序.xaml:
<Application x:Class="MainWin.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MainWin"
Startup="MainWindow.xaml">
</Application>
主窗口.xaml:
<Window x:Class="MainWin.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:MainWin"
mc:Ignorable="d"
Title="" Width="width" Height="height"
Loaded="Window_Load"
WindowState="Maximized"
WindowStartupLocation="CenterScreen"
WindowStyle="None"
AllowsTransparency="False"
Topmost="True"
Opacity="0">
<Grid x:Name="grid" Width="0" Height="0">
<MediaElement x:Name="name" Opacity="0" Visibility="Visible" LoadedBehavior="Play" MediaEnded="Media_Ended" Source="loc" Margin="0,0,0,0"/>
<Image Name="name" RenderOptions.BitmapScalingMode="HighQuality" Source="" Visibility="Hidden" Width="1400" Height="660" Opacity="0"/>
<Image Name="name" RenderOptions.BitmapScalingMode="HighQuality" Source="" Stretch="Fill" Visibility="Hidden" Width="20" Height="12" Opacity="0"/>
<Image Name="name" RenderOptions.BitmapScalingMode="HighQuality" Source="" Stretch="Fill" Visibility="Hidden" InkCanvas.Top="530" InkCanvas.Left="2330" Width="2000" Height="12" Opacity="0"/>
<Image Name="name" RenderOptions.BitmapScalingMode="HighQuality" Source="" Stretch="Fill" Visibility="Hidden" InkCanvas.Top="530" InkCanvas.Left="2330" Width="20" Height="12" Opacity="0"/>
<Image Name="name" RenderOptions.BitmapScalingMode="HighQuality" Source="" Stretch="Fill" Visibility="Hidden" Width="20" Height="12" Opacity="0"/>
<Image Name="name" RenderOptions.BitmapScalingMode="HighQuality" Source="loc" Stretch="Fill" Visibility="Hidden" Width="0" Height="12" Opacity="0"/>
<Image Name="name" RenderOptions.BitmapScalingMode="HighQuality" Source="loc" Stretch="Fill" Visibility="Hidden" Width="20" Height="12" Opacity="0"/>
<Label x:Name="name" Content="text" Width="712" HorizontalAlignment="Center" HorizontalContentAlignment="Center" Visibility="Hidden" Foreground="White" FontSize="font" FontFamily="font" FontWeight="Regular" Opacity="0"/>
<Label x:Name="name" Content="text" Width="1248" HorizontalAlignment="Center" HorizontalContentAlignment="Center" Foreground="White" FontSize="font" Visibility="Hidden" FontFamily="font" FontWeight="Regular" Opacity="0"/>
<Label x:Name="name" Content="text" Width="710" HorizontalAlignment="Center" HorizontalContentAlignment="Center" Visibility="Hidden" Foreground="White" FontSize="font" FontFamily="font" FontWeight="Regular" Opacity="0"/>
<Label x:Name="name" Content="text" Width="710" HorizontalAlignment="Center" HorizontalContentAlignment="Center" Visibility="Hidden" Foreground="White" FontSize="font" FontFamily="font" FontWeight="Regular" Opacity="0"/>
</Grid>
</Window>
我想删除应用程序启动时出现的黑屏。