English 中文(简体)
计算栏应当位于多国机器设备模型中?
原标题:Calculated columns should be where in MVVM model?
  • 时间:2012-01-15 13:35:26
  •  标签:
  • mvvm

我有一张WPF数据显示产品。 我有两种实际属于产品类别特性的田地价格和体质。 我需要用电网名称“多普利德瓦莱”显示一个排整栏。 如同MVVER模式那样,应当做些什么?

(1) 模范,只作读物。

2) 在兑换商中,只有我才知道这一点?

3)或观点模式?

请建议选择哪一种选择?

感谢。

最佳回答

从一开始,我就将忽略第2项选择——应只将转换器用于说明国际交易日志的执行细节,而具体来说,也许甚至到那时(因为你可以在“观点”内进行转换,即选择第3号,而且更方便)。

第1号与第3号之间,在这种情况下,IMHO最适于使用第1号——价格并非与贵方保单有关,当然,价格概念(及其衍生方式)将在整个应用过程中保持固定不变。 金融情报局和贵方均可选择使用这种财产。

问题回答

I would argue differently (than @jon). I put in the model only properties that I would like to serialize (say, from the server). Computed properties don t serialize, and hence they aren t in the model.

最近,我赞成的模式/意见模式如下: 产品是《示范法》中的一种类别,只有最简单的接收器和设计商。 产品 Vm是包含产品在内的低价竞标的一个类别,具有额外的低价竞标逻辑。 最重要的是,该财产改变了通知——我认为该通知也是证书的一部分,而不是模式。

// Model:
class Product {
    public double Price { get; set; }
    public double Mass { get; set; }
}

// View Model:
class ProductVM : INotifyPropertyChanged
{
    Product _product;
    public event PropertyChangedEventHandler PropertyChanged;

    public double Price {
        get { return _product.Price; }
        set { _product.Price = value; raise("Price"); raise("Total"); }
    }

    public double Mass {
        get { return _product.Mass; }
        set { _product.Mass = value; raise("Mass"); raise("Total"); }
    }

    public double total {
        get { return Price * Mass; }
    }

    private void raise(string name) {
        if( PropertyChanged ) {
            PropertyChanged( this, new PropertyChangedEventArgs(name) );
        }
    }

    public ProductVm( Product p ) {
        _product = p;
    }

    public ProductVm() {
        // in case you need this
        _product = new Product();
    }
}

是的,这里有许多碎块,但一旦你做所有打字,你就会发现,在《示范法》和《观点》之间,这种区分非常有益。 我的两点。

注:我认为“Jon”办法也是正确的,理由也是有效的。 我认为没有答案。





相关问题
Reactive Extensions (Rx) + MVVM =?

One of the main examples being used to explain the power of Reactive Extensions (Rx) is combining existing mouse events into a new event representing deltas during mouse drag: var mouseMoves = from ...

Where should the data be stored in MVVM?

I ve got this Silverlight Prism application that is using MVVM. The model calls a WCF service and a list of data is returned. The ViewModel is bound to the View, so the ViewModel should have a List ...

Where to put the calls to WCF or other webservices in MVVM?

I m building Silverlight applicaitions using Prism and MVVM. When calling WCF services on your own server, or even external webservices like the Bing api, would this be done from the Model? or from ...

How to avoid View specific code in my ViewModel

My application has a menu option to allow the creation of a new account. The menu option s command is bound to a command (NewAccountCommand) in my ViewModel. When the user clicks the option to create ...

WPF MVVM User Control binding issues

I have an application that uses MVVM. I have several items on the main window that bind to the ViewModel for that window. When I run it everything works. However, when I add a user control to the main ...

WPF: writing smoke tests using ViewModels

I am considering to write smoke tests for our WPF application. The question that I am faced is: should we use UI automation( or some other technology that creates a UI script), or is it good enough to ...

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

热门标签