Custom Style in pure MVVM

4 posts, 1 answers
  1. Jani
    Jani avatar
    61 posts
    Member since:
    Jan 2008

    Posted 24 Nov 2009 Link to this post

    I have a custom Style in my control Resources:
    <Style 
        x:Key="ActualScoreBarStyle" 
        TargetType="TelerikCharting:Bar"
        <Setter 
            Property="Template"
            <Setter.Value> 
                <ControlTemplate 
                    TargetType="TelerikCharting:Bar"
                    <Canvas> 
                        <Rectangle 
                            x:Name="PART_DefiningGeometry" 
                            Height="{TemplateBinding ItemActualHeight}" 
                            Width="{TemplateBinding ItemActualWidth}" 
                            RadiusX="2" 
                            RadiusY="2" 
                            Fill="{StaticResource RedBrush}" 
                            Stroke="Pink" 
                            StrokeThickness="3" /> 
                    </Canvas> 
                </ControlTemplate> 
            </Setter.Value> 
        </Setter> 
    </Style> 

    Based on the MVVM pattern (without code behind!) I have the following Chart:
    <TelerikChart:RadChart 
        ItemsSource="{Binding MyData}">
        ...
        <TelerikChart:RadChart.SeriesMappings> 
            <TelerikCharting:SeriesMapping> 
                <TelerikCharting:SeriesMapping.SeriesDefinition> 
                    ItemStyle="{StaticResource ActualScoreBarStyle}" /> 
                </TelerikCharting:SeriesMapping.SeriesDefinition> 
            </TelerikCharting:SeriesMapping> 
        </TelerikChart:RadChart.SeriesMappings>
        ...
    </TelerikChart:RadChart> 
     

    The code throws a System.Exception:
      at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
       at MS.Internal.XcpImports.UIElement_Measure(UIElement element, Size availableSize)
       at System.Windows.UIElement.Measure(Size availableSize)
       at Telerik.Windows.Controls.Charting.LinearSeriesPanel.MeasureOverride(Size availableSize)
       at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)

    Cheers,
    Jani


  2. Dwight
    Admin
    Dwight avatar
    475 posts

    Posted 27 Nov 2009 Link to this post

    Hi Jani,

    Can you, please, provide the structure of the data source you provide to the RadChart? There are no ItemMappings in the SeriesMapping.

    Best,
    Evtim
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Jani
    Jani avatar
    61 posts
    Member since:
    Jan 2008

    Posted 01 Dec 2009 Link to this post

    Hi Evtim

    Here is the complete XAML:
    <TelerikChart:RadChart 
        ItemsSource="{Binding MyData}"
        <TelerikChart:RadChart.DefaultView> 
            <TelerikCharting:ChartDefaultView> 
                <TelerikCharting:ChartDefaultView.ChartLegend> 
                    <TelerikCharting:ChartLegend 
                        Visibility="Collapsed" /> 
                </TelerikCharting:ChartDefaultView.ChartLegend> 
                <TelerikCharting:ChartDefaultView.ChartArea> 
                    <TelerikCharting:ChartArea 
                        EnableAnimations="False"
                        <TelerikCharting:ChartArea.AxisY> 
                            <TelerikCharting:AxisY 
                                AutoRange="False" 
                                MinValue="0" 
                                MaxValue="10" 
                                Step="1" /> 
                        </TelerikCharting:ChartArea.AxisY> 
                        <TelerikCharting:ChartArea.AxisX> 
                            <TelerikCharting:AxisX 
                                LabelRotationAngle="270" /> 
                        </TelerikCharting:ChartArea.AxisX> 
                    </TelerikCharting:ChartArea> 
                </TelerikCharting:ChartDefaultView.ChartArea> 
            </TelerikCharting:ChartDefaultView> 
        </TelerikChart:RadChart.DefaultView> 
             
        <TelerikChart:RadChart.SeriesMappings> 
            <TelerikCharting:SeriesMapping> 
                <TelerikCharting:SeriesMapping.SeriesDefinition> 
                    <TelerikCharting:BarSeriesDefinition 
                        ItemStyle="{StaticResource ActualScoreBarStyle}" 
                        ItemLabelFormat="0.0" /> 
                </TelerikCharting:SeriesMapping.SeriesDefinition> 
                <TelerikCharting:SeriesMapping.ItemMappings> 
                    <TelerikCharting:ItemMapping 
                        DataPointMember="YValue" 
                        FieldName="MyValue1" /> 
                    <TelerikCharting:ItemMapping 
                        DataPointMember="XCategory" 
                        FieldName="MyCaption1" /> 
                </TelerikCharting:SeriesMapping.ItemMappings> 
            </TelerikCharting:SeriesMapping> 
            <TelerikCharting:SeriesMapping> 
                <TelerikCharting:SeriesMapping.SeriesDefinition> 
                    <TelerikCharting:LineSeriesDefinition 
                        ShowItemLabels="False" /> 
                </TelerikCharting:SeriesMapping.SeriesDefinition> 
                <TelerikCharting:SeriesMapping.ItemMappings> 
                    <TelerikCharting:ItemMapping 
                        DataPointMember="YValue" 
                        FieldName="MyValue2" /> 
                    <TelerikCharting:ItemMapping 
                        DataPointMember="XCategory" 
                        FieldName="MyCaption2" /> 
                </TelerikCharting:SeriesMapping.ItemMappings> 
            </TelerikCharting:SeriesMapping> 
        </TelerikChart:RadChart.SeriesMappings> 
    </TelerikChart:RadChart> 
     
    Cheers,
    Jani


  4. Answer
    Dwight
    Admin
    Dwight avatar
    475 posts

    Posted 03 Dec 2009 Link to this post

    Hi Jani,

    Please, review your XAML for missing elements. I have created a test project using your templates.
    The only exception I managed to obtain was because of missing RedBrush resource.

    If you need further assistance, please, provide an application, that we can further analyze locally. To be able to attach projects, you will need to open support ticket (not a forum post).

    All the best,
    Evtim
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top