- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我刚刚开始开发 Windows 应用商店应用程序,我只想要一个非常简单的应用程序:几乎是一个从左到右填满的进度条,但即使是这个任务对我来说显然也无法完成。
我有以下代码:
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;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
namespace TimeLoader
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
private DispatcherTimer refreshTimer;
public MainPage()
{
this.InitializeComponent();
}
void refreshTimer_Tick(object sender, object e)
{
TimePassedBar.Value += 5;
}
private void Page_Loaded(object sender, RoutedEventArgs e)
{
TimePassedBar.Value = 50;
new DispatcherTimer();
this.refreshTimer = new DispatcherTimer();
this.refreshTimer.Interval = new TimeSpan(0, 0, 0, 100);
this.refreshTimer.Tick += refreshTimer_Tick;
this.refreshTimer.Start();
}
}
}
<Page
x:Class="TimeLoader.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TimeLoader"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" Loaded="Page_Loaded">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<ProgressBar Grid.Row="0" Grid.Column="0" Height="150" Value="75" VerticalAlignment="Center" Name="TimePassedBar"/>
</Grid>
</Page>
现在,当我在 WPF 中执行相同的设置时,它工作得很好,但是当我启 Action 为 Windows 商店应用程序构建的代码时,Tick 事件永远不会触发。构建 Windows 应用商店应用程序时有什么特别需要注意的吗?我四处寻找,遗憾的是在这件事上一无所获。
最佳答案
您的代码运行良好。你只是没有等足够长的时间来注意到。 :)
private void Page_Loaded(object sender, RoutedEventArgs e)
{
TimePassedBar.Value = 50;
this.refreshTimer = new DispatcherTimer();
this.refreshTimer.Interval = TimeSpan.FromMilliseconds(100);
this.refreshTimer.Tick += refreshTimer_Tick;
this.refreshTimer.Start();
}
您正在设置 TimeSpan
as 100 seconds .您需要使用五参数重载来获取毫秒数。但恕我直言,仅使用 FromMilliseconds()
方法(如上所述)更容易且更易读。
另外,您不需要两次创建 DispatcherTimer
对象,尤其是当您要完全忽略第一个对象时。 :)
关于c# - DispatcherTimer 不触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27413807/
问题一:您好,我想知道有没有一种方法可以处置或终止 DispatcherTimer 的对象并创建同名的新对象? 问题二:如果它设置为 Public,我可以访问其他类中的 DispatcherTimer
我很好奇为什么调度程序计时器在控制台模式下不起作用。我创建了一个简单的警报,当计时器达到限制时它会执行一些操作。 您可以在 UnitTest 或控制台模式下使用调度程序计时器吗?当我在表单中运行 Da
我想每隔几秒加载一张图片。我创建了 DispatcherTimer,我希望在计时器滴答中什么都不做,只是等待间隔。我该怎么做? if (window.DialogResult == true) {
我有一个应用程序的行为类似于自动刷新。它检查电子邮件、新视频、笑话等。 我的客户希望以不同的时间间隔检查这些单个元素。例如,每分钟发送一次电子邮件,每小时发送一次视频,等等。因此,他应该可以选择自己将
为什么在某些类中我必须指定此构造函数才能调用回调? _timer = new DispatcherTimer(DispatcherPriority.Normal, Application.Curren
我仍在学习 C#,我需要一些帮助。我有一个调度计时器,它每秒检查一次日期时间是否已初始化。它有效,但问题是它会继续做同样的事情,直到日期时间结束。例如,我希望 datetime 启动记事本。问题是 d
我正尝试在我的应用程序中使用三个按钮 - 开始、停止和重新启动来实现计时器。 计时器可以正常启动和停止。但是,当我单击重新启动按钮时,它从先前的秒和分钟值开始,而不是从 0 和 0 开始。我看不出我在
我正在尝试使用调度计时器,但我的 C# 应用找不到命名空间。这是错误: The type or namespace name 'DispatcherTimer' could not be found
我刚刚开始开发 Windows 应用商店应用程序,我只想要一个非常简单的应用程序:几乎是一个从左到右填满的进度条,但即使是这个任务对我来说显然也无法完成。 我有以下代码: using System;
如何重置 dispatcherTimer? 在我的应用程序中,我启动了一个计时器,稍后我使用 dispatcherTimer.Stop 方法停止,计时器停止。我关闭应用程序并再次运行它,但计时器并未从
我正在使用 DispatcherTimer 在 C# 中调用 void: counter = new System.Windows.Threading.DispatcherTimer(
我正在使用调度程序源计时器以不同的帧速率更新 View 。 (8、12 或 24 FPS) 这里是初始化dispatcherTimer的代码和用于创建计时器的函数。 (此函数直接取自苹果文档中的“创建
我需要用实时摄像机每秒捕捉 10 帧,持续 15 分钟。我使用了 dispatcherTimer 类,但它似乎不能正常工作。如何做到准确?我什至不保存图像,因为它很耗时,我只是将它保存在内存中,但它仍
我正在编写一个 Windows Phone 8.1 应用程序 (WINRT)。 我正在显示一个StatusBar: MYAPP(欢迎) MYAPP(通过 WIFI 连接) MYAPP(通过手机连接)
基本上,当我们应用某个时间间隔(即 5 秒)时,我们必须等待它。 是否可以应用间隔并立即执行计时器而不等待 5 秒?(我指的是间隔时间)。 有什么线索吗? 谢谢!! public partial cl
这些是我的 DispatcherTimer 声明和方法: private DispatcherTimer DishTimer; private TimeSpan SpanTime; private v
好的!这听起来像是“让我为你谷歌那个”,好吧,我做到了,这里是 MSDN 链接: http://msdn.microsoft.com/en-us/library/system.windows.thre
System.Windows.Forms.Timer() 和 System.Windows.Threading.DispatcherTimer() 有什么区别?在哪些情况下,我们应该使用它们?有什么最
我在使用 WPF 的项目上遇到问题。我正在尝试使用 DispatchTimer。我在另一个例子中看到 using DispatcherTimer = Windows.UI.Xaml.Dispatche
我在 StackOverflow 上看到了有关如何正确删除 WPF 中的控件的问题。通常有一些评论如何不手动(或不能)处理它们,只要您不持有对它们的引用,它们最终将被 GC 清除。我很偶然地注意到,我
我是一名优秀的程序员,十分优秀!