If whatever Axes is collecting isn't a class with it's own Name property then the DisplayMemberPath="Name" property may be causing you to not see anything.
Using a KeyedCollection as an ItemsSource is perfectly fine though. The ItemsSource property is the ItemsControl.ItemsSource property. And it merely requires that whatever it's bound to implements IEnumerable.
KeyedCollection does implement IEnumerable, as it implements Collection.
Here's a short sample using a KeyedCollection:
<Grid>
<DockPanel x:Name="QuickListButtonsStackPanel">
<Button DockPanel.Dock="Top"
Content="Load Animals"
Click="AnimalButtonClick" />
<Button DockPanel.Dock="Top"
Content="Load Objects"
Click="ObjectButtonClick" />
<TextBlock DockPanel.Dock="Bottom"
Background="Azure"
Text="{Binding SelectedExample}" />
<ListBox x:Name="uiListBox"
ItemsSource="{Binding Examples}"
SelectedItem="{Binding SelectedExample}" />
</DockPanel>
</Grid>
And the code for our Window & KeyedCollection:
public partial class Window1 : Window, INotifyPropertyChanged
{
public Window1()
{
InitializeComponent();
this.DataContext = this;
}
public KeyedCollection<char, string> Examples
{
get;
set;
}
private string mySelectedExample;
public string SelectedExample
{
get
{ return this.mySelectedExample; }
set
{
this.mySelectedExample = value;
this.NotifyPropertyChanged("SelectedExample");
}
}
private void AnimalButtonClick(object sender, RoutedEventArgs e)
{
Examples = new AlphabetExampleCollection();
Examples.Add("Ardvark");
Examples.Add("Bat");
Examples.Add("Cat");
Examples.Add("Dingo");
Examples.Add("Emu");
NotifyPropertyChanged("Examples");
}
private void ObjectButtonClick(object sender, RoutedEventArgs e)
{
Examples = new AlphabetExampleCollection();
Examples.Add("Apple");
Examples.Add("Ball");
Examples.Add("Chair");
Examples.Add("Desk");
Examples.Add("Eee PC");
NotifyPropertyChanged("Examples");
}
#region INotifyPropertyChanged Members
private void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
public event PropertyChangedEventHandler PropertyChanged;
#endregion
}
public class AlphabetExampleCollection : KeyedCollection<char, string>
{
public AlphabetExampleCollection() : base() { }
protected override char GetKeyForItem(string item)
{
return Char.ToUpper(item[0]);
}
}
The other issue that may be occurring is if you are just adding/removing items from the collection, and not re-setting the collection. In the example above, you can see that we are re-instating the keyed collection. If we didn't do this, then just calling NotifyPropertyChanged wouldn't do anything.
Lets add in two more buttons to demonstrate this:
<Button DockPanel.Dock="Top"
Content="Add Zebra"
Click="AddZebraClick" />
<Button DockPanel.Dock="Top"
Content="Add YoYo"
Click="AddYoYoClick" />
And the Hanlders:
private void AddZebraClick(object sender, RoutedEventArgs e)
{
Examples.Add("Zebra");
NotifyPropertyChanged("Examples");
}
private void AddYoYoClick(object sender, RoutedEventArgs e)
{
Examples.Add("YoYo");
NotifyPropertyChanged("Examples");
}
Both of these, as is will not work. When you call NotifyPropertyChanged the property has to actually be changed. And in this case, it is not. We've modified it's items, but the Examples collection is still the same collection. To fix this we could cycle the collection as we did in the first part, or if we have access to the UI, we could call:
uiListBox.Items.Refresh();
We could also cycle the DataSource, we could cycle the ListBox's ItemsSource, or we could clear and re-assign the binding but just calling UpdateTarget() won't do it however.