我正在显示来自服务器的图像。服务器中的图像每秒都在变化。我希望在我的应用程序中,图像应该在一秒钟后自动更改。M在Windows7编程中的新增功能。请告诉我在什么地方我缺乏概念。M使用此代码。这个过程将在我标记我的图像时开始。
private void image1_Tap(object sender, GestureEventArgs e)
{
System.Windows.Threading.DispatcherTimer dt = new System.Windows.Threading.DispatcherTimer();
dt.Interval = new TimeSpan(0, 0, 0, 0, 1000); // 500 Milliseconds
dt.Tick += new EventHandler(dt_Tick);
dt.Start();
}
这正在调用此方法。
void dt_Tick(object sender, EventArgs e)
{
status.Text = "chking" + counter++;
// Do Stuff here.
image1.Source = null;
Uri imgUri = new Uri(base_url,UriKind.Absolute);
BitmapImage BI = new BitmapImage(imgUri);
int H = BI.PixelHeight;
int w = BI.PixelWidth;
image1.Source = BI;
}
在这个代码中,我的计数器工作正常,状态良好。文本每秒都会成功更改。但形象一旦改变,就不会改变。金迪建议我在哪里犯错误。
提前感谢Gaurav Gupta
我认为您应该声明System.Windows.Threading.DispatcherTimer dt=new System.Windows.Tthreading.DDispatcherTime();作为成员变量,而不是在images tap事件中声明它。
我在wp8应用程序中从相机获取图像时也会做同样的事情。我将包含当前日期时间值的URL作为视图模型中的URL参数。当我想刷新时,我只需重置我的URL属性。
这是我的样品:这MyUrlProperty=字符串。格式("{0}?时间戳={1:yyyy-MM-dd HH:MM:ss:fff}",_originalCameraUrl,DateTime.Now);
非常适合我…