My Enum is not binding to my Contact Manager.
I have an Enum Class
[Serializable]
public enum Group
{
Friend,
Family,
Coworker
}
}
Then I have my MainWindow which initializes my Contact Manager
public partial class MainWindow : Window
{
//public List<Contact> ContactList = new List<Contact>();
public ObservableCollection<Contact> ContactList = new ObservableCollection<Contact>();
string fileName = null;
Contact furqan = new Contact("Herp Derp");
Contact rizwan = new Contact("Merp Meep");
public MainWindow()
{
InitializeComponent();
myItemsControl.ItemsSource = ContactList;
//myComboBox.ItemsSource = Enum.GetValues(typeof(Group));
//myComboBox.ItemsSource = Enum.GetValues(typeof(Group)).Cast<Group>();
furqan.HomePhone = "801238421";
ContactList.Add(furqan);
ContactList.Add(rizwan);
this.DataContext = this;
}
My XAML looks like this
<Label Grid.Row="7" Content="Home Email:"/>
<TextBox Grid.Row="7" Text="{Binding ElementName=myItemsControl, Path=SelectedItem.PersonalEmail, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
<Label Grid.Row="8" Content="Work Email:"/>
<TextBox Grid.Row="8" Text="{Binding ElementName=myItemsControl, Path=SelectedItem.WorkEmail, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
<Label Grid.Row="10" Content="Group:"/>
<ComboBox Grid.Row="10" Grid.Column="1" Text="{Binding ElementName=myItemsControl, Path=SelectedItem.ContactGroup, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
The ComboBox should display "CoWorker, Family, Friend" inside of it, but it doesn't, and it should bind with my Contact Class.
<ListBox x:Name="myItemsControl" Grid.Column="0" Grid.Row="1" Background="LightBlue">
<ItemsControl.ItemTemplate>
<DataTemplate x:Name="myDataTemplate">
<StackPanel>
<TextBlock Height="50" x:Name="contactName">
<Run FontSize="14" Text="{Binding Path=FirstName}"/>
<Run FontSize="14" Text="{Binding Path=LastName}"/>
</TextBlock>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ListBox>
How do I correctly bind this so it works with my Contact?
EDIT Everything works except for my Enums
All textboxes show what they are supposed to. Only the ComboBox doesn't work because it's not binded to all of the values that the Enum can be. I need to make an IEnumerable, maybe a ObservableCollection and add all of the values of the Group to it, and then bind to it. That works, however I have no idea how to bind my contactList(the observablecollection that's holding all of my contacts) to hold the Group collection. Any ideas?
Thanks!