tags:

views:

11

answers:

0

I am drawing framework elements to a drawingcontext using a visual brush. I want to disable all animation when I am doing this. My tests below do not work. When the code is called, a checkbox is draw and the check mark animates in.

My code using animation looks like this:


DrawingContext drawingContext; //from parameter

var checkbox = new CheckBox {
    Width = 100,
    Height = 30,
    IsChecked = true,
};

var visualBrush = new VisualBrush(checkbox);
var a = new DoubleAnimation { From = 0, To = 1, Duration =  new Duration(new TimeSpan(0)) };
visualBrush.BeginAnimation(UIElement.OpacityProperty, a);
drawingContext.DrawRectangle(visualBrush, null, new Rect(0, 0, 100, 30));

My code using storyboard looks like this:


DrawingContext drawingContext; //from parameter

var checkbox = new CheckBox {
    Width = 100,
    Height = 30,
    IsChecked = true,
};

var storyboard = new Storyboard();
//checkbox.BeginStoryboard(storyboard);
storyboard.Begin(checkbox);
storyboard.SkipToFill(checkbox);

var visualBrush = new VisualBrush(checkbox);
drawingContext.DrawRectangle(visualBrush, null, new Rect(0, 0, 100, 30));