tags:

views:

133

answers:

3

I have a Dictionary<string, FieldDefinition> dependency property that when I bind it to a WPF list box I want it to just print the string (not the FieldDefinition).

Is there a way to do that?

+1  A: 

Derive a class from Dictionary, override ToString().

Seva Alekseyev
+3  A: 

I would create a class that either implements IDictionary

public class CustomDictionary : IDictionary
{
...
}

or inherits Dictionary

public class CustomDictionary : Dictionary<string, FieldDefinition>
{
...
}

and override the ToString method in this class like this:

public override string ToString() 
  {
     return "My custom string";
  }
Joey
This is indeed the correct way to override ToString, but not quite what the OP is asking. IanR is on the right track there.
Igor Zevaka
+2  A: 

I could be wrong, here, but I think you are looking for the Keys property on the dictionary; this will return a collection of TKey values (in your case, the 'string' part of your dictionary, not the FieldDefinition part, which incidentally would be available via the Values Property)

<ListBox ItemsSource="{Binding MyDictionary.Keys}" />
IanR