[英]UnhandledException while using chart from winrt xaml toolkit
I am using charts of winrt xaml toolkit in my app. 我在我的应用程序中使用winrt xaml工具包的图表。 In certain screens chart works fine but in certain screens it now throws UnhandledException (earlier it was working fine. I didn't update ANYHTING).
在某些屏幕上,图表工作正常,但在某些屏幕上,它现在抛出UnhandledException(之前工作正常。我没有更新ANYHTING)。 I am not getting much exception details.
我没有太多例外细节。 What's wrong with the chart?
图表出了什么问题?
Exception details 例外详情
System.Exception at Windows.UI.Xaml.UIElement.Measure(Size availableSize) at WinRTXamlToolkit.Controls.DataVisualization.Charting.Primitives.EdgePanel.MeasureOverride(Size constraint) at Windows.UI.Xaml.FrameworkElement.MeasureOverride(Size availableSize)
WinRTXamlToolkit.Controls.DataVisualization.Charting.Primitives.EdgePanel.MeasureOverride(大小约束)处Windows.UI.Xaml.UIElement.Measure(大小可用大小)处的Windows.UI.Xaml.FrameworkElement.MeasureOverride(大小可用大小)
"Error HRESULT E_FAIL has been returned from a call to a COM component."
“从对COM组件的调用中返回了错误HRESULT E_FAIL。
Here's code to regenerate it. 这是重新生成它的代码。 I am doing all the stuff in code behind because in real app there would be dynamic number of charts.
我正在做代码背后的所有工作,因为在实际应用中,图表会动态变化。
XAML XAML
<Page.Resources>
<Style TargetType="charting:ColumnDataPoint" x:Key="MyColumnDataPointStyle">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="charting:ColumnDataPoint">
<Grid>
<ToolTipService.ToolTip>
<ContentControl>
<TextBlock Text="{Binding Tooltip}" TextAlignment="Center" />
</ContentControl>
</ToolTipService.ToolTip>
<Rectangle Fill="{Binding Color}" Stroke="{Binding Color}" StrokeThickness="3" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Page.Resources>
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<charting:Chart x:Name="ChartSalesRevenue" Margin="70,0" />
</Grid>
C# C#
protected override void OnNavigatedTo(NavigationEventArgs e)
{
ChartSalesRevenue.Series.Clear();
ChartSalesRevenue.Series.Add(new StackedColumnSeries());
Binding DependentBinding = new Binding();
Binding IndependentBinding = new Binding();
IndependentBinding.Converter = new DateToStringConverter();
SeriesDefinition series;
series = new SeriesDefinition();
series.DataPointStyle = this.Resources["MyColumnDataPointStyle"] as Style;
DependentBinding.Path = new PropertyPath("Units");
IndependentBinding.Path = new PropertyPath("Begin_Date");
series.DependentValueBinding = DependentBinding;
series.IndependentValueBinding = IndependentBinding;
series.ItemsSource = GetDataItems();
((StackedColumnSeries)ChartSalesRevenue.Series[0]).SeriesDefinitions.Add(series);
}
private List<DataItem> GetDataItems()
{
return new List<DataItem>
{
new DataItem("Tooltip 1", new SolidColorBrush(Colors.Red), 5, DateTime.Now.AddDays(-1)),
new DataItem("Tooltip 2", new SolidColorBrush(Colors.Violet), 3, DateTime.Now.AddDays(1)),
new DataItem("Tooltip 3", new SolidColorBrush(Colors.PaleGoldenrod), 22, DateTime.Now.AddDays(-2)),
new DataItem("Tooltip 4", new SolidColorBrush(Colors.DarkBlue), 15, DateTime.Now.AddDays(2)),
new DataItem("Tooltip 5", new SolidColorBrush(Colors.DeepPink), 9, DateTime.Now),
};
}
public class DateToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string Language)
{
return ((DateTime)value).ToString("MMM dd, yyyy", System.Globalization.CultureInfo.InvariantCulture);
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
public class DataItem
{
public DataItem(string _Tooltip, SolidColorBrush _Color, int _Units, DateTime _Begin_Date)
{
Tooltip = _Tooltip;
Color = _Color;
Units = _Units;
Begin_Date = _Begin_Date;
}
public string Tooltip { get; set; }
public SolidColorBrush Color { get; set; }
public int Units { get; set; }
public DateTime Begin_Date { get; set; }
}
I encountered the same problem and found a very easy solution. 我遇到了同样的问题,找到了一个非常简单的解决方案。
XAML XAML
<charting:Chart x:Name="ChartSalesRevenue" Margin="70,0" >
<charting:Stacked100BarSeries>
<charting:SeriesDefinition
DependentValuePath="Value"
IndependentValuePath="Name"
IsTapEnabled="True"
Title="" />
</charting:Stacked100BarSeries>
</charting:Chart>
C# C#
First in the page,add the Series("charting:Stacked100BarSeries").Before you add Series for Chart Control,Clear the Series . 在页面的第一部分,添加Series(“ charting:Stacked100BarSeries”)。为图表控件添加Series之前,请清除Series。
eg: 例如:
ChartSalesRevenue.Series.Clear();
ChartSalesRevenue.Series.Add(...);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.