Я хочу использовать изображение GIF (с анимацией) в качестве заставки в приложении UWP.Но я не знаю, как этого добиться.Я нахожу какую-то ссылку, чтобы дать какое-то решение, но кажется, что они не для приложения UWP.Как этот: https://social.msdn.microsoft.com/Forums/en-US/3fe32aae-84cb-47fe-a2b0-6650ce22e25c/splashscreen-that-loads-an-animated-gif?forum=vssmartdevicesvbcs
private void Form1_Load(object sender, EventArgs e)
{
String imgPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.ToString()) + "\\Ani.gif";
StringBuilder sb = new StringBuilder();
sb.Append("<html><body>");
sb.Append("<img src = \"" + imgPath + "\">");
sb.Append("</body></html>");
webBrowser1.DocumentText = sb.ToString();
}
У вас есть работоспособное решение для приложения UWP?Пожалуйста, порекомендуйте.Спасибо!
Подробнее:
Проверяя, г-н Чжу дает ссылку, я делаю GIF-заставку, и она работает.Но есть новая проблема: до того, как GIF-шоу будет, возможно, будет 5s белый экран.Как это убрать?Новый тестовый код выглядит следующим образом:
Package.appxmanifest
: закомментировать исходный png-файл заставки
<!--<uap:SplashScreen Image="Assets\SplashScreen.png" />-->
App.xaml.cs:
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
if (e.PreviousExecutionState != ApplicationExecutionState.Running)
{
bool loadState = (e.PreviousExecutionState == ApplicationExecutionState.Terminated);
ExtendedSplash extendedSplash = new ExtendedSplash(e.SplashScreen, loadState);
Window.Current.Content = extendedSplash;
}
Window.Current.Activate();
}
ExtendedSplash.xaml :
<Page
x:Class="SplashScreenExample.ExtendedSplash"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:SplashScreenExample"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="#464646">
<Image x:Name="extendedSplashImage" Source="Assets/test.gif"/>
</Grid>
ExtendedSplash.xaml.cs :
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.ApplicationModel.Activation;
using Windows.UI.Core;
using System.Diagnostics;
using Windows.UI.ViewManagement;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace SplashScreenExample
{
partial class ExtendedSplash : Page
{
internal Rect splashImageRect; // Rect to store splash screen image coordinates.
private SplashScreen splash; // Variable to hold the splash screen object.
internal bool dismissed = false; // Variable to track splash screen dismissal status.
internal Frame rootFrame;
// Define methods and constructor
public ExtendedSplash(SplashScreen splashscreen, bool loadState)
{
InitializeComponent();
ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.FullScreen;
splash = splashscreen;
if (splash != null)
{
// Register an event handler to be executed when the splash screen has been dismissed.
splash.Dismissed += new TypedEventHandler<SplashScreen, Object>(DismissedEventHandler);
// Retrieve the window coordinates of the splash screen image.
splashImageRect = splash.ImageLocation;
splashImageRect.Width = 1092;
splashImageRect.Height = 1080;
splashImageRect.X = 0;
splashImageRect.Y = 0;
}
// Create a Frame to act as the navigation context
rootFrame = new Frame();
}
// Include code to be executed when the system has transitioned from the splash screen to the extended splash screen (application's first view).
void DismissedEventHandler(SplashScreen sender, object e)
{
dismissed = true;
// Complete app setup operations here...
}
void DismissExtendedSplash()
{
// Navigate to mainpage
rootFrame.Navigate(typeof(MainPage));
// Place the frame in the current Window
Window.Current.Content = rootFrame;
}
}
}