启动应用程序时删除黑屏

时间:2019-02-19 05:06:01

标签: c# wpf windows performance application-start

我创建了一个C#WPF应用程序。在这种情况下,我的UI组件有限(标签,MediaElement,图像源(4))。我正在用最大化的窗口加载我的应用程序。 当我启动exe时,黑屏显示一秒钟,然后出现实际的UI。

我设置了一个属性,即AllowsTranparency = True。它解决了上述问题,但要花一个新的钱,即,如果将此属性设置为true,则MediaElement中播放的视频会滞后很多。

因此,该解决方案是排除在外的。

App.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>

Main Window.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>

我要删除应用程序启动时出现的黑屏。

1 个答案:

答案 0 :(得分:0)

更改Background="Color you want"Window的透明标签。