本文介绍了如何在OnRender中重绘或刷新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想动态绘制一些东西。以下代码显示了我的OnRender。我在程序中需要的地方设置了DrawItem。但是,当我打电话给 DrawItem = 5; 时,我该怎么打,以便调用OnRender?

I want to draw something dynamically. Following code shows my OnRender. I'm setting DrawItem somewhere in my program where I need it. But when I'm calling DrawItem =5; what do I have to call, so that OnRender gets called?

protected override void OnRender(DrawingContext drawingContext)
{
    switch (DrawItem)
    {
        case 1:
            //Draw Item 
            break;
        case 2:
            //Draw Item 
            break;
        case 3:
            //Draw Item 
            break;
        case 4:
            //Draw Item 
            break;
        case 5:
            //Draw Item 
            break;
    }
    base.OnRender(drawingContext)
}

public int DrawItem { get; set; }


推荐答案

您的问题尚不清楚,但从我可以了解您似乎在要求一种在更新绘图变量后刷新视觉效果的方法。更新绘图变量后,可以使用以下代码:

Your question is not clear but from what I can understand you seem to be asking for a method to refresh the visuals after updating your drawing variables. You could use the following after updating your drawing variables:

this.InvalidateVisual();

并具有以下属性:

private int drawItem;
pulic int DrawItem
{
 get {return drawItem;}
 set 
 {
    drawItem=value;
    this.InvalidateVisual();
 }
}

这篇关于如何在OnRender中重绘或刷新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 01:57