Binding IsReadOnly using IValueConverter

Posted by mastur cheef on Stack Overflow See other posts from Stack Overflow or by mastur cheef
Published on 2013-11-04T21:12:31Z Indexed on 2013/11/04 21:53 UTC
Read the original article Hit count: 397

Filed under:
|
|

Maybe I'm misunderstanding how to use an IValueConverter or data binding (which is likely), but I am currently trying to set the IsReadOnly property of a DataGridTextColumn depending on the value of a string. Here is the XAML:

<DataGridTextColumn Binding="{Binding Path=GroupDescription}" Header="Name"
                    IsReadOnly="{Binding Current,
                                 Converter={StaticResource currentConverter}}"/>

And here is my converter:

public class CurrentConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        string s = value as string;
        if (s == "Current")
        {
            return false;
        }
        else
        {
            return true;
        }
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotSupportedException();
    }
}

Currently, the column is always editable, the converter seems to do nothing. Does anyone have some thoughts as to why this is happening?

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf