I have a situation where a TabControl's ItemsSource is bound to a collection of view models, which then generates a TabItem for each view model. Each Tab Item view model will implement very similar base functionality (for example, commands related to Save, New, Delete, and overriding ToString(), etc.).
Based on the code sample below, is this the right way to construct the child view models, with a parameterized constructor in the base class? I'm not too familiar with Generics, but does this situation lend itself to a Generic base class somehow? Any feedback is greatly appreciated.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WpfApplication1
{
public abstract class PartViewModel : ViewModelBase
{
public PartTypeEnum PartType { get; set; }
ICommand Save { get; set; }
ICommand New { get; set; }
ICommand Delete { get; set; }
public PartViewModel(PartTypeEnum partType)
{
PartType = partType;
}
public override string DisplayName
{
get { return this.ToString(); }
}
public override string ToString()
{
return EnumHelper.GetEnumDescription(PartType);
}
}
public class Part1ViewModel : PartViewModel
{
public Part1ViewModel() : base(PartTypeEnum.Part1)
{
}
}
public class Part2ViewModel : PartViewModel
{
public Part2ViewModel() : base(PartTypeEnum.Part2)
{
}
}
// etc...
}
I don't think it does. What would be the different acceptable types of your generic type T?
ICommand
is your abstraction, no matter the Part of the ViewModel, your ICommand should be sufficient.
I'm also unsure why you have an enumeration? Doesn't the enumeration do pretty much the same thing as the different derived classes?
I have a situation where a TabControl's ItemsSource is bound to a collection of view models, which then generates a TabItem for each view model. Each Tab Item view model will implement very similar base functionality (for example, commands related to Save, New, Delete, and overriding ToString(), etc.).
Based on the code sample below, is this the right way to construct the child view models, with a parameterized constructor in the base class? I'm not too familiar with Generics, but does this situation lend itself to a Generic base class somehow? Any feedback is greatly appreciated.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WpfApplication1
{
public abstract class PartViewModel : ViewModelBase
{
public PartTypeEnum PartType { get; set; }
ICommand Save { get; set; }
ICommand New { get; set; }
ICommand Delete { get; set; }
public PartViewModel(PartTypeEnum partType)
{
PartType = partType;
}
public override string DisplayName
{
get { return this.ToString(); }
}
public override string ToString()
{
return EnumHelper.GetEnumDescription(PartType);
}
}
public class Part1ViewModel : PartViewModel
{
public Part1ViewModel() : base(PartTypeEnum.Part1)
{
}
}
public class Part2ViewModel : PartViewModel
{
public Part2ViewModel() : base(PartTypeEnum.Part2)
{
}
}
// etc...
}
I don't think it does. What would be the different acceptable types of your generic type T?
ICommand
is your abstraction, no matter the Part of the ViewModel, your ICommand should be sufficient.
I'm also unsure why you have an enumeration? Doesn't the enumeration do pretty much the same thing as the different derived classes?
0 commentaires:
Enregistrer un commentaire