I need to bind a List<Key>
to TextBox
. I've written a converter which converts from List<Key>
to string (the ConvertBack
method just throws an exception - it isn't used). Problem is that when I try to use this converter, it shows me an error: The TypeConverter for "IValueConverter" does not support converting from a string. It appears that the problem is caused because it's trying to convert string
from TextBox
to List<Key>,
but I don't want to do that (user won't "write" to this TextBox
). I've already thought about using something else than TextBox
- perhaps TextBlock
which I think would solve the problem, but I'd like to use TextBox
for some other reasons.
My property I want to bind:
public partial class Settings : Window
{
public List<Key> hotkeyCapture_keys { get; set; }
...
Converter:
class ListKeyToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return string.Join(" + ", (List<Key>)value);
}
...
And TextBox:
<TextBox ... Text="{Binding hotkeyCapture_keys, Converter=ListKeyToStringConverter}" />
When try to Build it, the app immediately shuts down with "XamlParseException occured".
Can anyone tell me how to solve this problem?
Thanks