【问题标题】:Assembly reference issues with WPF Metro ChartWPF Metro Chart 的装配参考问题
【发布时间】:2018-08-08 01:58:47
【问题描述】:

所以我正在尝试使用 Torsten Mandelkow ModernUICharts NuGet 包。 我能够在一个新的解决方案中按照他的Codeplex 上的文档进行操作,并且图表显示出来并且没有问题填充。问题是当我尝试在我的项目中执行此操作时,我收到错误消息:

类型引用找不到名为“ChartBase”的公共类型。第 18 行位置 75。

我已确保我已在两个项目之间准确地复制了多次代码,但我始终得到相同的结果。我试过在 Stack Overflow 上查找它1234 没有成功。

这是我的代码:

App.xaml

<Application x:Class="ReqTotalWPF.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:chart="clr-namespace:De.TorstenMandelkow.MetroChart;assembly=De.TorstenMandelkow.MetroChart"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
            <!-- Accent and AppTheme setting -->
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />

        </ResourceDictionary.MergedDictionaries>
            <Style x:Key="MinimalChartStyle" TargetType="chart:ChartBase">
                <Setter Property="Width" Value="500"/>
                <Setter Property="Height" Value="500"/>
            </Style>
        </ResourceDictionary>
    </Application.Resources>
</Application>

ViewModel.cs

public class ReqTotalViewModel:ObservableObject
{ 
    class TestPageViewModel
    {
        public ObservableCollection<TestClass> Errors { get; private set; }

        public TestPageViewModel()
        {
            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;
            }
        }
    }

    public class TestClass
    {
        public string Category { get; set; }
        public int Number { get; set; }
    }
}

MainWindow.xaml

<Controls:MetroWindow x:Class="ReqTotalWPF.MainWindow"
                      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                      xmlns:d="clr-namespace:ReqTotalWPF"
                      Title="ReqTotals" Height="800" Width="963"
                      xmlns:xctk ="http://schemas.xceed.com/wpf/xaml/toolkit"
                      xmlns:xcdg ="http://schemas.xceed.com/wpf/xaml/datagrid"
                      xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
                      xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
                      xmlns:metroChart="clr-namespace:De.TorstenMandelkow.MetroChart;assembly=De.TorstenMandelkow.MetroChart"
                      WindowStartupLocation="CenterScreen"
                      xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro">
  <Grid Background="#2F2C38"
         HorizontalAlignment="Stretch"
         VerticalAlignment="Stretch"
         Grid.Row="1">
      <Grid.RowDefinitions>
          <RowDefinition Height="25"/>
          <RowDefinition Height="30*"/>
      </Grid.RowDefinitions>
      <StackPanel Grid.Row="1">
          <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>
      </StackPanel>
  </Grid>

MainWindow.xaml.cs

public partial class MainWindow : MetroWindow
{
    public MainWindow()
    {
        InitializeComponent();
        this.DataContext = new ReqTotalViewModel();
    }
}

任何帮助将不胜感激。谢谢!

【问题讨论】:

  • 不确定,但也许它适用于您的情况。尝试使用将
  • 谢谢,但这并没有解决问题。当我添加它时,它确实让我了解了问题所在。输出显示它在切换并更正 this.DataContext = new TestPageViewModel(); 后试图运行 4.0 而不是 4.5 的框架;指向正确的视图模型。而不是 ReqTotalViewModel() (在 MainWindows.xaml.cs 中)

标签: c# .net wpf xaml reference


【解决方案1】:

我进入 Project->Application-> Target framework 将其切换到 4.5。

MainWindows.xaml.cs

public partial class MainWindow : MetroWindow
{
    public MainWindow()
    {
        InitializeComponent();
        this.DataContext = new ReqTotalViewModel();

    }
}

public partial class MainWindow : MetroWindow
{
    public MainWindow()
    {
        InitializeComponent();
        this.DataContext = new TestPageViewModel();

    }
}

【讨论】:

    猜你喜欢
    • 2015-07-21
    • 1970-01-01
    • 2012-09-19
    • 2022-07-15
    • 2011-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多