gpt4 book ai didi

c# - 现代 UI (Metro) 图表 WPF 未显示

转载 作者:行者123 更新时间:2023-11-30 16:55:35 25 4
gpt4 key购买 nike

我正在为我的项目使用 .NET Framework 4.5 和 WPF。我需要生成多种类型的图表,所以我想使用 http://modernuicharts.codeplex.com/库来做到这一点。我按照该 codeplex 页面中的文档进行操作:http://modernuicharts.codeplex.com/documentation并完成了这些步骤。

现在我在 Visual Studio 13 中没有收到任何类型的错误或警告消息,只是图表没有显示。我只能看到图表的标题和副标题。

此问题的可能原因是什么以及如何纠正它们?

谢谢

XAML 代码:

<Canvas Margin="570,90,29,92" Background="White" >
<chart:PieChart
Style="{StaticResource MinimalChartStyle}"
ChartTitle="Minimal Pie Chart"
ChartSubTitle="Chart with fixed width and height"
SelectedItem="{Binding Path=SelectedItem, Mode=TwoWay}" >
<chart:PieChart.Series>
<chart:ChartSeries
SeriesTitle="Errors"
DisplayMember="Category"
ValueMember="Number"
ItemsSource="{Binding Path=Errors}" />
</chart:PieChart.Series>
</chart:PieChart>
</Canvas>

用作 dataContext 的 ViewModel 类:

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ModernUIForWPFSample.WithoutBackButton.Views
{
public class MainViewModel
{
public ObservableCollection<TestClass> Errors { get; private set; }

public MainViewModel()
{
Errors = new ObservableCollection<TestClass>();
Errors.Add(new TestClass() { Category = "Globalization", Number = 75 });
Errors.Add(new TestClass() { Category = "Features", Number = 2 });
Errors.Add(new TestClass() { Category = "ContentTypes", Number = 12 });
Errors.Add(new TestClass() { Category = "Correctness", Number = 83});
Errors.Add(new TestClass() { Category = "Best Practices", Number = 29 });
}

private object selectedItem = null;
public object SelectedItem
{
get
{
return selectedItem;
}
set
{
// selected item has changed
selectedItem = value;
}
}
}

// class which represent a data point in the chart
public class TestClass
{
public string Category { get; set; }

public int Number { get; set; }
}

}

在代码中 Bihind :

public FinalAnalysis()
{
InitializeComponent();
this.DataContext = new MainViewModel();
}

最佳答案

这是一个工作示例:

应用 XAML:

<Application x:Class="WpfApplication1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml"
xmlns:chart="clr-namespace:De.TorstenMandelkow.MetroChart;assembly=De.TorstenMandelkow.MetroChart">
<Application.Resources>
<ResourceDictionary>
<Style x:Key="MinimalChartStyle" TargetType="chart:ChartBase">
<Setter Property="Width" Value="500"/>
<Setter Property="Height" Value="500"/>
</Style>
</ResourceDictionary>
</Application.Resources>
</Application>

主窗口 XAML:

<Window 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WpfApplication1.MainWindow"
Title="MainWindow" Height="1500" Width="1525"
xmlns:metroChart="clr-namespace:De.TorstenMandelkow.MetroChart;assembly=De.TorstenMandelkow.MetroChart">


<metroChart:PieChart
Style="{StaticResource MinimalChartStyle}"
ChartTitle="Minimal Pie Chart"
ChartSubTitle="Chart with fixed width and height"
SelectedItem="{Binding Path=SelectedItem, Mode=TwoWay}" >
<metroChart:PieChart.Series>
<metroChart:ChartSeries
SeriesTitle="Errors"
DisplayMember="Category"
ValueMember="Number"
ItemsSource="{Binding Path=Errors}" />
</metroChart:PieChart.Series>
</metroChart:PieChart>

</Window>

主窗口 :

public MainWindow()
{

InitializeComponent();
DataContext = new MainViewModel();
}

MainWindowViewModel 和你的一样,这里就不复制粘贴了。注意装配声明:

 xmlns:metroChart="clr-namespace:De.TorstenMandelkow.MetroChart;assembly=De.TorstenMandelkow.MetroChart"

并且不要忘记在 App xaml 中添加样式

关于c# - 现代 UI (Metro) 图表 WPF 未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29315053/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com