I'm not sure what to do as far as managing the _namePrefixes for this control. I know I can make it non-static, but it makes sense to be static to be consistent across all uses of this control in terms of content for my project. Also, I chose ObservableCollection because of the following scenario:
I have 2 client machines, one for standard use, the other for managing options (admin) such as a Name Prefix list. If the client is running and the admin makes a change, the client should update itself and reflect those changes after it has already been loaded. Oh, and because this is a WPF item and I wanna databind it to a ListBox. If neither of these make me use an ObserableCollection, no big deal... I'll use something like a List, but I don't think that'll change the original question.
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace MyProject
{
public class NameField : TextBox
{
private static ObservableCollection<NamePrefix> _namePrefixes;
private static ObservableCollection<NameSuffix> _nameSuffixes;
static NameField()
{
_namePrefixes = new ObservableCollection<NamePrefix>();
_nameSuffixes = new ObservableCollection<NameSuffix>();
}
public static void AddNamePrefix(Int32 id, String prefix)
{
//TODO: WHAT DO I DO HERE!?
}
}
/// <summary>
/// A Key/Value structure containing a Name Prefix ID and String value.
/// </summary>
public struct NamePrefix
{
#region Constructor
public NamePrefix(Int32 id, String prefix)
: this()
{
ID = id;
Prefix = prefix;
}
#endregion
#region Properties (ID, Prefix)
public Int32 ID { get; set; }
public String Prefix { get; set; }
#endregion
}
/// <summary>
/// A Key/Value structure containing a Name Suffix ID and String value.
/// </summary>
public struct NameSuffix
{
#region Constructor
public NameSuffix(Int32 id, String suffix)
: this()
{
ID = id;
Suffix = suffix;
}
#endregion
#region Properties (ID, Prefix)
public Int32 ID { get; set; }
public String Suffix { get; set; }
#endregion
}
}