0

我刚刚创建了一个名为 Tipcalc>core 的 PCL,我正在构建它的女巫的教程就是这个。这是我的 TipViewModel.cs

using Cirrious.MvvmCross.ViewModels;

namespace TipCalc.Core
{
public class TipViewModel : MvxViewModel
{
    private readonly ICalculation _calculation;
    public TipViewModel(ICalculation calculation)
    {
        _calculation = calculation;
    }

    public override void Start()
    {
        _subTotal = 100;
        _generosity = 10;
        Recalcuate();
        base.Start();
    }

    private double _subTotal;

    public double SubTotal
    {
        get { return _subTotal; }
        set { _subTotal = value; RaisePropertyChanged(() => SubTotal); Recalcuate(); }
    }

    private int _generosity;

    public int Generosity
    {
        get { return _generosity; }
        set { _generosity = value; RaisePropertyChanged(() => Generosity); Recalcuate(); }
    }

    private double _tip;

    public double Tip
    {
        get { return _tip; }
        set { _tip = value; RaisePropertyChanged(() => Tip); }
    }

    private void Recalcuate()
    {
        Tip = _calculation.TipAmount(SubTotal, Generosity);
    }
}
 }

问题是当我创建这个 PCL 时,出现以下错误:

Error   1   The type or namespace name 'ICalculation' could not be found (are you missing a using directive or an assembly reference?)
TipCalc.Core
Error   2   The type or namespace name 'ICalculation' could not be found (are you missing a using directive or an assembly reference?)

尽管我的界面和类,都在项目的服务文件夹中。

计算.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TipCalc.Core.Services
{
public class Calculation : ICalculation
{
    public double TipAmount(double subTotal, int generosity)
    {
        return subTotal * ((double)generosity) / 100.0;
    }
}
 }

和 ICalculation.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TipCalc.Core.Services
{
 public interface ICalculation
{
    double TipAmount(double subTotal, int generosity);
}
}

请问有什么帮助吗?

4

1 回答 1

0

您需要在 Calculation.cs 中添加 using

使用 ICalculation.cs

使用 TipCalc.Core.Services;

于 2013-07-25T16:13:26.907 回答