This is a migrated thread and some comments may be shown as answers.

Catastrophic Failure

2 Answers 85 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Aaron
Top achievements
Rank 2
Aaron asked on 29 Oct 2010, 08:41 PM
Hi,

I'm trying to simply have my chart's legend items wrap their text, rather than being cuttoff. 

Pretty basic thing really.  I was surprised to hear how complicated it was to do this.  I followed the instructions at http://www.telerik.com/help/silverlight/radchart-styling-and-appearance-styling-chart-legend.html, but I'm getting an error before I even change anything. As soon as I set the LegendItemStyle in the ChartLegendStyle via a setter, Visual Studio underlines the whole line in blue squigly, and holding the mouse over the squigly yields the error message: "Catastrophic Failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED)).

Here is my code.  I chose to edit the style in a copy, stored in App.xaml. 
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
             xmlns:System="clr-namespace:System;assembly=mscorlib" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" 
             x:Class="GarciaCharts.App"
             >
    <Application.Resources>
        <SolidColorBrush x:Key="LegendForeground" Color="#FF000000"/>
        <LinearGradientBrush x:Key="LegendBackground" EndPoint="1.96,0.5" StartPoint="-0.96,0.5">
            <GradientStop Color="#FF0000FF"/>
            <GradientStop Color="#FFF0F0F0" Offset="0.5"/>
        </LinearGradientBrush>
        <SolidColorBrush x:Key="LegendBorderBrush" Color="#FF848484"/>
        <Thickness x:Key="LegendBorderThickness">1</Thickness>
        <telerik:TextToVisibilityConverter x:Key="textToVisibilityConverter"/>
        <Style x:Key="ChartLegendStyle1" TargetType="telerik:ChartLegend">
            <Setter Property="Foreground" Value="{StaticResource LegendForeground}"/>
            <Setter Property="Background" Value="{StaticResource LegendBackground}"/>
            <Setter Property="Padding" Value="10,10,10,5"/>
            <Setter Property="Margin" Value="0"/>
            <Setter Property="LegendItemStyle" Value="{StaticResource ChartLegendItemStyle1}"/>
            <Setter Property="BorderBrush" Value="{StaticResource LegendBorderBrush}"/>
            <Setter Property="BorderThickness" Value="{StaticResource LegendBorderThickness}"/>
            <Setter Property="TitleFontWeight" Value="Bold"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="telerik:ChartLegend">
                        <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}">
                            <Grid Margin="{TemplateBinding Padding}">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="*"/>
                                </Grid.RowDefinitions>
                                <ContentControl ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" Foreground="{TemplateBinding Foreground}" FontWeight="{TemplateBinding TitleFontWeight}"/>
                                <ItemsPresenter Grid.Row="1"/>
                            </Grid>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="ItemsPanel">
                <Setter.Value>
                    <ItemsPanelTemplate>
                        <telerik:RadWrapPanel Orientation="{Binding ItemsPanelOrientation}"/>
                    </ItemsPanelTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="HeaderTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <Grid>
                            <TextBlock FontSize="12" HorizontalAlignment="Left" Height="Auto" Padding="0,0,0,2" TextWrapping="Wrap" Text="{Binding}" Visibility="{Binding Converter={StaticResource textToVisibilityConverter}}" Width="Auto"/>
                        </Grid>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <LinearGradientBrush x:Key="LegendItemMarkerMask" EndPoint="0.5,1" StartPoint="0.5,0">
            <GradientStop Color="#D8FFFFFF" Offset="0.009"/>
            <GradientStop Color="#66FFFFFF" Offset="1"/>
            <GradientStop Color="Transparent" Offset="0.43"/>
            <GradientStop Color="#7FFFFFFF" Offset="0.42"/>
        </LinearGradientBrush>
        <SolidColorBrush x:Key="LegendItemMarkerMaskOpacityMask" Color="#FF000000"/>
        <SolidColorBrush x:Key="LegendItemMarkerMaskStroke" Color="White"/>
        <System:Double x:Key="LegendItemMarkerMaskStrokeThickness">1</System:Double>
        <SolidColorBrush x:Key="LegendItemMarkerMask2" Color="Transparent"/>
        <Style x:Key="ChartLegendItemStyle1" TargetType="telerik:ChartLegendItem">
            <Setter Property="Foreground" Value="{StaticResource LegendForeground}"/>
            <Setter Property="Padding" Value="5,0,5,0"/>
            <Setter Property="Margin" Value="0,3,0,2"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="telerik:ChartLegendItem">
                        <Grid x:Name="PART_MainContainer" HorizontalAlignment="Stretch" VerticalAlignment="Top">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="HoverStates">
                                    <VisualState x:Name="Normal">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0.00:00:00.15" To="1.0" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PART_MainContainer"/>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Hovered">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0.00:00:00.15" To="1.0" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PART_MainContainer"/>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Hidden">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0.00:00:00.15" To="0.15" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PART_MainContainer"/>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="SelectionStates">
                                    <VisualState x:Name="Unselected"/>
                                    <VisualState x:Name="Selected">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Duration="0.00:00:00.05" Storyboard.TargetProperty="Stroke" Storyboard.TargetName="PART_LegendItemMarker">
                                                <DiscreteObjectKeyFrame KeyTime="0.00:00:00.0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <SolidColorBrush Color="#B2000000"/>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Duration="0.00:00:00.05" Storyboard.TargetProperty="StrokeThickness" Storyboard.TargetName="PART_LegendItemMarker">
                                                <DiscreteObjectKeyFrame KeyTime="0.00:00:00.0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <System:Double>2</System:Double>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Duration="0.00:00:00.05" Storyboard.TargetProperty="StrokeThickness" Storyboard.TargetName="PART_SelectedState">
                                                <DiscreteObjectKeyFrame KeyTime="0.00:00:00.0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <System:Double>0</System:Double>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Path x:Name="PART_LegendItemMarker" Data="" Height="16" Margin="{TemplateBinding Margin}" Style="{TemplateBinding ItemStyle}" Stretch="Fill" StrokeThickness="{TemplateBinding MarkerStrokeThickness}" Width="16"/>
                            <Path x:Name="PART_SelectedState" Data="" Fill="{StaticResource LegendItemMarkerMask}" Height="14" Margin="{TemplateBinding Margin}" OpacityMask="{StaticResource LegendItemMarkerMaskOpacityMask}" Stretch="Fill" Stroke="{StaticResource LegendItemMarkerMaskStroke}" StrokeThickness="{StaticResource LegendItemMarkerMaskStrokeThickness}" Width="14"/>
                            <Path Data="" Fill="{StaticResource LegendItemMarkerMask2}" Height="14" Margin="{TemplateBinding Margin}" Stretch="Fill" Width="14"/>
                            <TextBlock x:Name="PART_TextBlock" Grid.Column="1" Foreground="{TemplateBinding Foreground}" Margin="{TemplateBinding Margin}" Padding="{TemplateBinding Padding}" Text="{TemplateBinding Label}"/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Application.Resources>
</Application>

2 Answers, 1 is accepted

Sort by
0
Aaron
Top achievements
Rank 2
answered on 03 Nov 2010, 12:54 AM
I figured out the answer to this.

When you edit styles in Blend, and you choose to store them in App.xaml, blend adds the elements in the order that you edit them.

But because the LegendItemStyle getter (in ChartLegendStyle) refers to the ChartLegendItemStyle that you edit, the ChartLegendItemStyle needs to be defined first.

Basically, the order that you define your styles matter.  The tutorial probably could have been more explicit about that.
0
Nikolay
Telerik team
answered on 03 Nov 2010, 11:51 AM
Hi Aaron,

Thank you for your suggestion, we will forward your request and update the tutorial.Your feedback is greatly appreciated.

Sincerely yours,
Nikolay
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Chart
Asked by
Aaron
Top achievements
Rank 2
Answers by
Aaron
Top achievements
Rank 2
Nikolay
Telerik team
Share this question
or