构建时MVVM出错

时间:2013-07-25 11:38:01

标签: mvvm visual-studio-2012 namespaces

我刚刚创建了一个名为Tipcalc> core的PCL,我正在构建它的教程是one。这是 我的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?)

Altough我的界面和类,就在项目的服务文件夹中。

Calculation.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);
}
}

有什么帮助吗?

1 个答案:

答案 0 :(得分:0)

您需要在Calculation.cs中添加使用

使用ICalculation.cs

使用TipCalc.Core.Services;