The widget is not updated after the property is set in code

Problem with Widget redrawing

 

You probably faced the following problem: you try to change something in widget visual presentation, for example size of an element, its fill or border width, but after setting the corresponding property widget is not changed. Such behavior is caused by the following particularity: to make widget understand the changes and update it it is necessary to inform a widget about this manually. There are two methods for this:

setNeedRepaint(bool needRepaint)

and

refreshElement().

This way first of all you mark some elements of a widget that they need redrawing and then initiate redrawing of a widget by the refreshElement method. In one of next product version we will fix this problem and redrawing will be called automatically.

 

<script type="text/javascript">
    var widget;
    var slider;
    var circle;
    var fillHi;
    var fillLow;
 
    window.onload = function () {
        //widget model
        var jsonModel = <JSON>
 
        //creating widget
        widget = new PerfectWidgets.Widget("root", jsonModel);
 
        //getting slider object
        slider = widget.getByName("Slider1");
        slider.addValueChangedHandler( updateFill )
 
        //getting circle object
        circle = widget.getByName("Circle1");
 
        fillHi = new PerfectWidgets.Framework.Drawing.LinearGradientFill();
        fillHi.setStartColor(PerfectWidgets.Framework.Drawing.Color.red);
        fillHi.setEndColor(PerfectWidgets.Framework.Drawing.Color.blue);
        fillLow = new PerfectWidgets.Framework.Drawing.LinearGradientFill();
        fillLow.setStartColor(PerfectWidgets.Framework.Drawing.Color.green);
        fillLow.setEndColor(PerfectWidgets.Framework.Drawing.Color.yellow);
    }
 
    function updateFill(sender, e) {
 
    var fill;
 
    if (sender.getValue() < 60){
        circle.setFill(fillLow);
    }else{
        circle.setFill(fillHi);
    }
 
    circle.setNeedRepaint(true);
    circle.refreshElement();
}
</script>


 

 

Add Feedback