2013-09-24 21 views
0

當我讀到這一行時:有沒有模型可以有一個視圖和viewmodel?

viewmodel不僅暴露模型,還暴露其他屬性(例如狀態信息,如「忙」指示符)和命令。

http://www.codeproject.com/Articles/100175/Model-View-ViewModel-MVVM-Explained

我想知道在視圖當前設置是否應被視爲國家的視圖或部分的財產,並放置在一個視圖模型。

例如我目前有一個偏好窗口綁定到一個視圖模型,包含當前的顏色和一堆綁定到視圖模型的顏色選擇器。然後命令取消更改並重新應用舊設置,如果單擊確定或取消。

當前顏色應該是視圖上的屬性,還是當前位置正確?

public class PreferencesWindowViewModel:DependencyObject 
    { 
    private DelegateCommand updatePreferencesCommand; 

    public ICommand UpdatePreferencesCommand 
    { 
     get { return updatePreferencesCommand; } 
    } 
    private DelegateCommand cancelCommand; 

    public ICommand CancelCommand 
    { 
     get { return cancelCommand; } 
    } 

    public Color HighValuePenColor 
    { 
     get { return (Color)GetValue(HighValuePenColorProperty); } 
     set 
     { 
     SetValue(HighValuePenColorProperty, value); 
     } 
    } 
+2

[不要使用視圖模型的DependencyObjects](http://kentb.blogspot.com.ar/2009/03/view-models-pocos-versus.html) –

+0

是啊我注意到最近一邊查看討論依賴對象vs inotifypropertychanged的文章。儘管如此,我還沒有回去改變他們 –

回答

1

我喜歡他們在視圖模型上。出於簡單的原因,這個功能可以在單元測試線束中測試。如果他們看到了這個觀點,你將不得不跳過更多的箍環來測試它。在我看來,視圖模型應該包含大部分的表示邏輯。顏色及其與某些應用程序狀態的關係屬於該類別的代碼。

相關問題