您的位置:程序门 -> .net技术 -> c#



wpf 如何避免画面闪烁


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


wpf 如何避免画面闪烁
发表于:2007-03-27 10:34:23 楼主
我在canvas上加入一个rectangle,然后开一个线程,每40毫秒,修改一下rectangle的width和height属性,每次加1,但是我发觉rectangle会闪,似乎是wpf先擦掉了这个rectangle,画了一遍背景,然后又重绘rectangle,有什么办法能不闪吗?
发表于:2007-03-27 10:46:171楼 得分:0
不懂vpf   帮顶
发表于:2007-03-27 11:15:322楼 得分:0
该回复于2007-10-26 14:40:27被管理员删除
发表于:2007-03-27 11:31:563楼 得分:0
不知道
发表于:2007-03-27 11:40:024楼 得分:0
使用故事板,这样画面变化会平滑一些,尽量不要自己使用线程直接改变元素的属性
发表于:2007-03-27 13:14:555楼 得分:0
同意ls

用storyboard

在expression   blend,画一矩型,按f7,进入animation   workspace.
增加一个event,增加一个action,   在时间线开始处增加一个关键帧,在时间线适当地方按住shift键放大矩型。ok,that 's   all.

有点像flash里做动画似的。没有闪烁~
发表于:2007-03-27 15:13:366楼 得分:0
我用了animation也闪,我在试试storyboard吧
发表于:2007-03-27 15:19:387楼 得分:0
mark
发表于:2007-03-27 15:53:278楼 得分:0
up
发表于:2007-03-27 16:47:379楼 得分:0
是的,别在线程里修改位置
发表于:2007-03-27 19:56:1310楼 得分:0
我在线程里调用form的invoke,是form的线程修改位置的,canvas是form的子窗口
发表于:2007-03-27 20:00:4611楼 得分:0
参考:

在wpf的用户线程中更新ui界面  
 
wpf中ui线程队列由dispatcher来管理和调度,所以当用户线程中更新ui时,必须通过dispatche来调度,下面这个小例子将给用户展示如何在用户线程中更新当前的时间.
 
前台的xaml代码如下:
<windowx:class= "threadinvoke.window1 "
        xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation "
        xmlns:x= "http://schemas.microsoft.com/winfx/2006/xaml "
        title= "threadinvoke "height= "300 "width= "300 "
        >
  <stackpanelorientation= "vertical ">
        <stackpanelorientation= "horizontal ">
            <buttoncontent= "ok "click= "okclick "width= "50 "/>
            <buttoncontent= "stop "click= "stopclick "width= "50 "/>
        </stackpanel>
        <textboxname= "timetext "> </textbox>
  </stackpanel>
</window>
 
后台的主要代码如下:
 
//申明一个代理用于想ui更新时间
private   delegate   void   delegatesetcurrenttime();
 
//申明一个变量,用于停止时间的跳动
private   bool   stopflag   =   false;
 
//处理开始和结束事件
private   void   okclick(object   sender,routedeventargs   args)
{
                        stopflag   =   false;
                        thread   thread   =   new   thread(new   threadstart(refreshtime));
                        thread.start();
}
 
private   void   stopclick(object   sender,   routedeventargs   args)
{
                        stopflag   =   true;
}
 
//用户线程的实现函数
private   void   refreshtime()
{
                        while   (!stopflag)
                        {
//向ui界面更新时钟显示                                 dispatcher.invoke(system.windows.threading.dispatcherpriority.systemidle,   new   delegatesetcurrenttime(setcurrenttime));
                        }
}
 
private   void   setcurrenttime()
{
                        string   currenttime   =   system.datetime.now.tostring();
                        timetext.text   =   currenttime;
}
发表于:2007-03-27 21:09:2812楼 得分:0
靠,看来落后了!!
发表于:2007-03-27 21:37:1313楼 得分:0
郁闷啊,看了半天都不知道嘛意思
发表于:2007-03-27 22:32:5314楼 得分:0
前几天刚了解了一下wpf,xaml,还可把环境搭上了
发表于:2007-03-28 14:01:1515楼 得分:0
非常感谢namhyuk提供的跨线程修改ui的方法,但是闪烁的问题仍然存在


快速检索

最新资讯
热门点击