0

I have created a C# WPF application. In that i have limited UI components (label, MediaElement, Image sources(4)). I am loading my application with maximized window. When I launch my exe, a Black screen is shown for a second and the actual UI appears.

I set one property i.e., AllowsTranparency = True. It solves the above problem but on cost of a new one i.e., If this property is set to true, the Video played in MediaElement lags a lot.

So, this solution is ruled out.

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>

I want to remove the Black screen that comes on launch of the application.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Ashish Rana
  • 135
  • 1
  • 11
  • Change `Opacity="1"` – Gopichandar Feb 19 '19 at 05:10
  • Doesn't help. By doing this for window, instead of black screen, white screen comes, then black screen comes and the the actual MainWindow Ui is shown. – Ashish Rana Feb 19 '19 at 05:17
  • Share your code in `Window_Load` – Gopichandar Feb 19 '19 at 05:19
  • The large images that the window xaml is referring to might cause a delay while initializing the window. Try removing them (and other slow elements) and setting them in the window's loaded event. This might allow the UI thread to draw the qindow earlier. – Emond Feb 19 '19 at 06:10
  • @Gopichandar Code in Window_Load:- HwndSource source = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle); source.AddHook(new HwndSourceHook(METHOD_NAME)); – Ashish Rana Feb 19 '19 at 07:28
  • @Erno de Weerd I tried removing all the slow elements but still same issue persists. – Ashish Rana Feb 19 '19 at 07:28

1 Answers1

0

Change the Background="Color you want" or Transparent of Window tag.

Subhash Saini
  • 254
  • 4
  • 5