1
我的視圖模型MyViewModel有一個屬性MyProperty,我需要從應用程序的設置中讀取/保存/保存。我的項目有Settings.settings文件,Settings類型有MyProperty屬性。我需要將MyViewModel.MyProperty綁定到Settings.MyProperty,以便任何對MyViewModel.MyProperty的更改都反映在Settings.MyProperty中,並可能以其他方式反映出來。我怎樣才能做到這一點?如何將我的視圖模型屬性綁定到應用程序設置?
請注意,我無法從設置派生MyViewModel,因爲MyViewModel已經派生出另一種類型。
編輯:我可以手動做到這一點:從我的屬性定義中讀取和寫入設置,但我問是否有更優雅的方法。
class MyViewModel : ViewModelBase
{
public int MyProperty { ... }
public MyViewModel()
{
// here i need to bind Settings.Default.MyProperty to this.MyProperty
}
}
請問您是否可以用代碼片段來詳細說明? – Pat 2011-06-23 15:46:23