使用图像周围的圆形进度条获取扩展的启动画面
Get Extended Splashscreen With Circular ProgressBar Around Image
我正在使用模板 10,并希望我的启动画面看起来像这样:
我搞定了循环进度条控件Here and got it around a image through Grace Feng help from this code
现在我想将这一轮进度控制放入我的启动画面,所以它看起来像上面的图像,但在扩展的启动画面 link 教程中,他们通过 canvas 显示它,我想做它由 Myprogress 控制任何想法如何在扩展启动中实现此控制 screen.If 我只是在 splash.xaml 中使用它然后我的应用程序构建并启动但然后它 hangs.But 删除它运行的控制 perfectly.Any 帮助将不胜感激。
谢谢。
在 Grace Feng 示例中出现此错误:
but in the extended splash screen link tutorial they show it by canvas and i want to do it by Myprogress control any idea how to implement this control in extended splash screen.
虽然在official document中使用了Canvas
来显示扩展启动画面的内容,但是不需要和文档中的代码完全一样,文档中的代码只是为了一个例子。即使您不需要为扩展启动画面创建新的空白页面,您也可以创建一个 UserControl
来执行此操作。
关于使用Extended Splash Screen in Template 10
的一些信息,您可以参考Template10: a new template to create Universal Windows apps – The basics。
所以这是我的例子,我创建了一个名为 ExtendedSplash
:
的 UserControl
<Grid Background="#00b2f0">
<mycontrols:RoundProgressControl x:Name="ProgressControl" HorizontalAlignment="Center" VerticalAlignment="Center"
Size="300" LineWidth="8" Color="Orange" />
</Grid>
后面的代码很简单,就是处理循环进度条的TimeTikcer:
public sealed partial class ExtendedSplash : UserControl
{
private Timer TheTimer = null;
private object LockObject = new object();
private double ProgressAmount = 0;
public ExtendedSplash()
{
this.InitializeComponent();
this.Loaded += (sender, e) =>
{
TimerCallback tcb = HandleTimerTick;
TheTimer = new Timer(HandleTimerTick, null, 0, 30);
};
this.Unloaded += (sender, e) =>
{
lock (LockObject)
{
if (TheTimer != null)
TheTimer.Change(Timeout.Infinite, Timeout.Infinite);
TheTimer = null;
}
};
}
public void HandleTimerTick(Object state)
{
lock (LockObject)
{
ProgressControl.SetBarLength(ProgressAmount);
ProgressAmount += 0.006;
if (ProgressAmount > 1.5)
ProgressAmount = 0.0;
}
}
}
要使用此 ExtendedSplash
,您可以在 App.xaml.cs 文件代码中像这样:
sealed partial class App : Template10.Common.BootStrapper
{
public App()
{
InitializeComponent();
SplashFactory = e => new ExtendedSplash();
}
public override async Task OnInitializeAsync(IActivatedEventArgs args)
{
await Task.CompletedTask;
}
public override async Task OnStartAsync(StartKind startKind, IActivatedEventArgs args)
{
await Task.Delay(TimeSpan.FromSeconds(6));
NavigationService.Navigate(typeof(Views.MainPage));
}
}
使用SplashFactory
的原因在我上面提供的博客中有解释。你可以找到我的 sample here.
更新:
首先,这个错误代码不是我的代码,这是你提供的循环进度条。这是一个基于 COM 的 API 错误代码。错误消息非常清楚:消息过滤器表明应用程序正忙。正如你所说,"while it is in hanged state",出现了这个错误。
一个简单的方法来处理这个异常,你可以像这样在这段代码中添加一个"try catch":
public void SetBarLength(double Value)
{
try
{
if (DesignMode.DesignModeEnabled)
SetBarLengthUI(Value);
else if (CoreApplication.MainView.CoreWindow.Dispatcher.HasThreadAccess)
SetBarLengthUI(Value);
else
{
double LocalValue = Value;
IAsyncAction IgnoreMe = CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { SetBarLengthUI(Value); });
}
}
catch (Exception e)
{
Debug.WriteLine(e.ToString());
}
}
我正在使用模板 10,并希望我的启动画面看起来像这样:
我搞定了循环进度条控件Here and got it around a image through Grace Feng help from this code
现在我想将这一轮进度控制放入我的启动画面,所以它看起来像上面的图像,但在扩展的启动画面 link 教程中,他们通过 canvas 显示它,我想做它由 Myprogress 控制任何想法如何在扩展启动中实现此控制 screen.If 我只是在 splash.xaml 中使用它然后我的应用程序构建并启动但然后它 hangs.But 删除它运行的控制 perfectly.Any 帮助将不胜感激。 谢谢。
在 Grace Feng 示例中出现此错误:
but in the extended splash screen link tutorial they show it by canvas and i want to do it by Myprogress control any idea how to implement this control in extended splash screen.
虽然在official document中使用了Canvas
来显示扩展启动画面的内容,但是不需要和文档中的代码完全一样,文档中的代码只是为了一个例子。即使您不需要为扩展启动画面创建新的空白页面,您也可以创建一个 UserControl
来执行此操作。
关于使用Extended Splash Screen in Template 10
的一些信息,您可以参考Template10: a new template to create Universal Windows apps – The basics。
所以这是我的例子,我创建了一个名为 ExtendedSplash
:
UserControl
<Grid Background="#00b2f0">
<mycontrols:RoundProgressControl x:Name="ProgressControl" HorizontalAlignment="Center" VerticalAlignment="Center"
Size="300" LineWidth="8" Color="Orange" />
</Grid>
后面的代码很简单,就是处理循环进度条的TimeTikcer:
public sealed partial class ExtendedSplash : UserControl
{
private Timer TheTimer = null;
private object LockObject = new object();
private double ProgressAmount = 0;
public ExtendedSplash()
{
this.InitializeComponent();
this.Loaded += (sender, e) =>
{
TimerCallback tcb = HandleTimerTick;
TheTimer = new Timer(HandleTimerTick, null, 0, 30);
};
this.Unloaded += (sender, e) =>
{
lock (LockObject)
{
if (TheTimer != null)
TheTimer.Change(Timeout.Infinite, Timeout.Infinite);
TheTimer = null;
}
};
}
public void HandleTimerTick(Object state)
{
lock (LockObject)
{
ProgressControl.SetBarLength(ProgressAmount);
ProgressAmount += 0.006;
if (ProgressAmount > 1.5)
ProgressAmount = 0.0;
}
}
}
要使用此 ExtendedSplash
,您可以在 App.xaml.cs 文件代码中像这样:
sealed partial class App : Template10.Common.BootStrapper
{
public App()
{
InitializeComponent();
SplashFactory = e => new ExtendedSplash();
}
public override async Task OnInitializeAsync(IActivatedEventArgs args)
{
await Task.CompletedTask;
}
public override async Task OnStartAsync(StartKind startKind, IActivatedEventArgs args)
{
await Task.Delay(TimeSpan.FromSeconds(6));
NavigationService.Navigate(typeof(Views.MainPage));
}
}
使用SplashFactory
的原因在我上面提供的博客中有解释。你可以找到我的 sample here.
更新:
首先,这个错误代码不是我的代码,这是你提供的循环进度条。这是一个基于 COM 的 API 错误代码。错误消息非常清楚:消息过滤器表明应用程序正忙。正如你所说,"while it is in hanged state",出现了这个错误。
一个简单的方法来处理这个异常,你可以像这样在这段代码中添加一个"try catch":
public void SetBarLength(double Value)
{
try
{
if (DesignMode.DesignModeEnabled)
SetBarLengthUI(Value);
else if (CoreApplication.MainView.CoreWindow.Dispatcher.HasThreadAccess)
SetBarLengthUI(Value);
else
{
double LocalValue = Value;
IAsyncAction IgnoreMe = CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { SetBarLengthUI(Value); });
}
}
catch (Exception e)
{
Debug.WriteLine(e.ToString());
}
}