【问题标题】:silverlight charting no initial animation for printing (printing in series of data)silverlight 图表没有用于打印的初始动画(打印一系列数据)
【发布时间】:2010-08-26 20:42:47
【问题描述】:

我有点吃不消了。 我需要生成图表(屏幕外,因此用户看不到它们)并使这些图表可以保存。这意味着设置基础知识并从加载的图表构建图像。 我说的是柱状图仅供参考:)

问题在于内置的缓动动画。当图表触发“加载”事件时,我会生成要保存的图像,因此图表上还没有任何内容。

我已经尝试了几件事:

  • 可能在渲染结束时触发的不同事件
  • 延迟构建图像(但这不是万无一失的)

到目前为止,我所有的谷歌搜索都提出了在没有动画的情况下重新模板化数据点(我找不到任何参考,这是一个主要问题,我唯一能找到的是关于 StylePalette 的东西,无处可寻在程序集中)

在这方面的任何帮助将不胜感激。

编辑:

我移植到我的主要 mvvm 解决方案,这使我将其放入自定义控件中。 在与同事合作后,我们决定控件应该从一系列数据(列表列表)中生成一系列图像(以 WriteableBitmaps 的形式)。

这可以通过遍历列表并呈现我需要的内容来完成。当然在可见的可视化树之外,因为图像必须添加到客户端生成的文档中。

这让我想到了下一个问题。因为我无法订阅 LayoutUpdated 事件(因为它被几乎所有东西触发)我有点卡住了。 控件上有 1 个图表不断加载新数据,这反过来又导致加载的事件仅发生一次。我需要一个解决方案(各种事件),让我知道所有数据都已呈现,以便我可以提取屏幕截图并放入一些新数据...

帮助?

【问题讨论】:

    标签: silverlight printing charts


    【解决方案1】:

    此链接可能很有趣,因为您遇到的问题应该与您尝试打印图表时类似:http://www.davidpoll.com/2010/04/16/making-printing-easier-in-silverlight-4/

    基本上(假设您无法重新模板化系列 [使用 Expression Blend 更容易!])您可以通过调用 SkipToFill() 遍历可视化树并“完成”任何故事板。

    从上面提到的链接:

     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);
        }
    

    【讨论】:

    • 我查看了您在上面发布的链接 :) 我尝试了代码 sn-p,但由于某种原因,它似乎对我没有多大用处。无论我在哪里启动代码以填充动画,它都会不断出现仅绘图画布和图例。为什么没有将渲染事件插入图表? :(
    • 好吧,这很不幸,但几乎更好,因为我认为这更像是一个黑客而不是一个适当的解决方案。我建议您给 Blend 一个机会并重新模板化数据点。这并不难。 :-)
    【解决方案2】:

    我所做的是添加这种样式:

    <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>
    

    它将动画折叠成任何东西,但仍然不能成为防弹解决方案......

    我仍然需要一个要订阅的事件。我编辑了我的原始问题以添加更多细节......

    【讨论】:

      猜你喜欢
      • 2019-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-10
      • 1970-01-01
      • 1970-01-01
      • 2019-05-15
      • 2023-03-02
      相关资源
      最近更新 更多