views:

70

answers:

2

Hey guys,

I'm in a bit of a pickle. I need to generate charts (off screen so the user doesn't see them) and make these charts save-able. this means setting up the basics and building an image from the loaded chart. I'm talking about a columnseries chart fyi :)

the problem is the built-in ease-in animation. as the chart triggers the "loaded" event I generate an image to save and thus nothing is on the chart yet.

I've tried several things:

  • different events that could trigger at the end of render
  • delaying the building of the image (but that's not bulletproof)

thus far all my googling searches come up with retemplating the datapoints without the animation (for which I cannot find any reference which is a major problem, the only thing I can find is something concerning a StylePalette, what is nowhere to be found in the assemblies)

any help in this area would be greatly appreciated.

EDIT:

I ported to my main mvvm solution, which made me put this into a custom control. after some collaboration with colleagues we decided the control should produce a series of images (in the form of WriteableBitmaps) from a series of data (lists of lists).

this can be done by just running through the list and rendering what I need. Outside of the visible visualtree of course since the images have to be added to a document which is generated clientside.

this brings me to the next puddle of problems. since I cannot subscribe to the LayoutUpdated event (as it get's triggered by virtually EVERYTHING) I'm a little stuck. There's 1 chart on the control that is constantly loaded with new data, which in turn causes the loaded event only to happen once. I need a solution (event of sorts) that let's me know all data is rendered so I can pull the screenshot and put in some new data...

help?

A: 

This link may be of interest as the problem you are facing should be similar as when you try printing the chart: http://www.davidpoll.com/2010/04/16/making-printing-easier-in-silverlight-4/

Basically (assuming you cannot re-template the series [much easier with Expression Blend!]) you can traverse the visual tree and "complete" any storyboard by calling SkipToFill().

From the above mentioned link:

 private static void DriveAnimationsToCompletion(FrameworkElement element)
    {
        if (element == null)
            return;
        var groups = VisualStateManager.GetVisualStateGroups(element);
        foreach (VisualStateGroup group in groups)
        {
            foreach (
                Storyboard board in group.Transitions.Cast<VisualTransition>().Select(trans => trans.Storyboard)
                    .Concat(group.States.Cast<VisualState>().Select(state => state.Storyboard))
                    .Where(board => board.GetCurrentState() != ClockState.Stopped))
            {
                board.SkipToFill();
            }
        }
        foreach (
            FrameworkElement child in
                Enumerable.Range(0, VisualTreeHelper.GetChildrenCount(element)).Select(
                    index => VisualTreeHelper.GetChild(element, index)).OfType<FrameworkElement>())
            DriveAnimationsToCompletion(child);
    }
Francesco De Vittori
I've looked at the link you posted above :)I tried the code snippet and for some reason it doesn't seem to do much good on my end. Wherever I Launch the code to fill the animations it keeps coming up with just the drawing canvas and legend.why wasn't a rendered-event inserted into the charts? :(
Jan W.
Ok, that's unfortunate, but almost better as I think it was more of a hack than a proper solution.I suggest you give Blend a chance and re-template the datapoint. It isn't really that hard. :-)
Francesco De Vittori
A: 

what I did is add this style:

<Style x:Key="customColumnDataPoint" TargetType="chartingToolkit:ColumnDataPoint">
    <Setter Property="Background" Value="DarkBlue"/>
    <Setter Property="BorderBrush" Value="Black"/>
    <Setter Property="BorderThickness" Value="1"/>
    <Setter Property="IsTabStop" Value="False"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="chartingToolkit:ColumnDataPoint">
                <Border
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}"
                    x:Name="Root">
                    <VisualStateManager.CustomVisualStateManager>
                        <ei:ExtendedVisualStateManager/>
                    </VisualStateManager.CustomVisualStateManager>
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="CommonStates">
                            <VisualStateGroup.Transitions>
                                <VisualTransition GeneratedDuration="0"/>
                            </VisualStateGroup.Transitions>
                            <VisualState x:Name="Normal"/>
                            <VisualState x:Name="MouseOver">
                            </VisualState>
                        </VisualStateGroup>
                        <VisualStateGroup x:Name="SelectionStates">
                            <VisualStateGroup.Transitions>
                                <VisualTransition GeneratedDuration="0"/>
                            </VisualStateGroup.Transitions>
                            <VisualState x:Name="Unselected"/>
                            <VisualState x:Name="Selected">
                                <Storyboard>
                                    <DoubleAnimation
                                        Storyboard.TargetName="SelectionHighlight"
                                        Storyboard.TargetProperty="Opacity"
                                        To="0.6"
                                        Duration="0"/>
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                        <VisualStateGroup x:Name="RevealStates">
                            <VisualStateGroup.Transitions>
                                <VisualTransition GeneratedDuration="0"/>
                            </VisualStateGroup.Transitions>
                            <VisualState x:Name="Shown">
                                <Storyboard>
                                    <DoubleAnimation
                                        Storyboard.TargetName="Root"
                                        Storyboard.TargetProperty="Opacity"
                                        To="1"
                                        Duration="0"/>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="Hidden">
                                <Storyboard>
                                    <DoubleAnimation
                                        Storyboard.TargetName="Root"
                                        Storyboard.TargetProperty="Opacity"
                                        To="1"
                                        Duration="0"/>
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                    <Grid
                        Background="{TemplateBinding Background}">
                        <Rectangle>
                            <Rectangle.Fill>
                                <LinearGradientBrush>
                                    <GradientStop
                                        Color="#77ffffff"
                                        Offset="0"/>
                                    <GradientStop
                                        Color="#00ffffff"
                                        Offset="1"/>
                                </LinearGradientBrush>
                            </Rectangle.Fill>
                        </Rectangle>
                        <Border
                            BorderBrush="#ccffffff"
                            BorderThickness="1">
                            <Border
                                BorderBrush="#77ffffff"
                                BorderThickness="1"/>
                        </Border>
                        <Rectangle x:Name="SelectionHighlight" Fill="Red" Opacity="0"/>
                        <Rectangle x:Name="MouseOverHighlight" Fill="White" Opacity="0"/>
                    </Grid>
                    <ToolTipService.ToolTip>
                        <ContentControl Content="{TemplateBinding FormattedDependentValue}"/>
                    </ToolTipService.ToolTip>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

it folds the animation to nothing but still doesn't make a bulletproof solution...

I still need an event to which to subscribe. I edited my original question to add some more specifics ...

Jan W.