0
用下面的業務對象:在模型中直接使用業務對象的DependencyProperty是否有意義?
public class ItemsRow : BusinessObject<ItemsRow>
{
public static readonly DependencyProperty ItemIdProperty = DependencyProperty.Register("ItemId", typeof(int), typeof(ItemsRow));
public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register("Description", typeof(string), typeof(ItemsRow));
public int ItemId
{
get { return (int)this.GetValue(ItemIdProperty); }
set { this.SetValue(ItemIdProperty, value); }
}
public string Description
{
get { return (string)this.GetValue(DescriptionProperty); }
set { this.SetValue(DescriptionProperty, value); }
}
}
你會如何在一個模型暴露的屬性,看到的性能如何已的DependencyProperty的?
我在想,如果它將使任何意義,這樣做:
public class ItemModel: DependencyObject
{
Item _item;
public ItemModel(Item item)
{
_item = item;
}
public static readonly DependencyProperty DescriptionProperty = Item.DescriptionProperty;
public string Description
{
get { return _item.Description; }
set { _item.Description = value; }
}
}
將這項工作作爲預期或將模型一定要有自己的一套的DependencyProperty年代由業務對象的DependencyProperty的支持?或者可以稍微修改以正確工作?
我個人認爲這是一個不好的做法,對模特屬性(除非有很好的理由),該模型是不適合的地方 - 如果這發生在一個視圖模型之間則區別和模型趨向變得不存在。 – slugster
@slugster老實說,我認爲我應該調用ItemViewModel。剛剛學習這些東西,以前剛學過MVC。現在我正在回顧一下我正在建模的MVVM示例,我注意到示例項目中甚至沒有Model.cs文件讓我困惑。 –
謝謝Ameen,那是我的一種想法,但只是想仔細檢查是否可以採取任何捷徑。爲了迴應你答案的最後一句話,一個典型的模型(或ViewModel ...你可以從上面的評論中看到,我現在對此有點困惑)會引用多個業務對象。如果模型只引用單個業務對象,那麼我可能會直接使用業務對象。 –