質問

I bound my text box to property (only text box) and used converter which just return opposite bool value.

XAML

<TextBox Height="23" HorizontalAlignment="Left" Margin="13,41,0,0" Text="{Binding Path=CurrentProfile.profileName}"  IsEnabled="{Binding Path=CurrentProfile.isPredefined, Converter={StaticResource PredefinedToControlEnabled}}" VerticalAlignment="Top" Width="247" Grid.ColumnSpan="2" TabIndex="1" />

Converter

public class PredefinedToControlEnabled: IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        var isPredefined = (bool)value;
        return !isPredefined;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

When the property value isPredefined is true, the IsEnabled property of TextBox is set correctly to false. When the isPredefined is false, the converter returns false and all controls on GUI sets IsEnabled property to false, what means that application is not useable anymore (it works in background naturally). Why it is happening?

How does it look like:

enter image description here

役に立ちましたか?

解決

Found,

VS automagically add line to Window properties

IsEnabled="{Binding Path=CurrentProfile.isPredefined}"

but the question still is, how?

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top