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

[Solved] Custom Style in pure MVVM

3 Answers 132 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jani
Top achievements
Rank 1
Jani asked on 24 Nov 2009, 03:30 PM
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


3 Answers, 1 is accepted

Sort by
0
Dwight
Telerik team
answered on 27 Nov 2009, 02:04 PM
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.
0
Jani
Top achievements
Rank 1
answered on 01 Dec 2009, 10:46 AM
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


0
Accepted
Dwight
Telerik team
answered on 03 Dec 2009, 09:59 AM
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.
Tags
Chart
Asked by
Jani
Top achievements
Rank 1
Answers by
Dwight
Telerik team
Jani
Top achievements
Rank 1
Share this question
or