0
我將我的文本框綁定到屬性(僅文本框)並使用了僅返回相反bool值的轉換器。爲什麼使用轉換器進行綁定更改不會綁定到GUI上的屬性?
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" />
轉換
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();
}
}
當isPredefined的屬性值是true,TextBox的IsEnabled屬性被正確地設置爲false。當isPredefined爲false時,轉換器返回false,GUI上的所有控件將IsEnabled屬性設置爲false,意味着該應用程序不再可用(它在後臺自然工作)。爲什麼會發生?
它是如何看起來像:
是你的問題解決了嗎? – Sankarann
是否嘗試將'UpdateSourceTrigger = PropertyChanged'添加到您的IsEnabled屬性? 'IsEnabled =「{Binding Path = CurrentProfile.isPredefined,Converter = {StaticResource PredefinedToControlEnabled},UpdateSourceTrigger = PropertyChanged}」' – phil
是的,修復發現。屬性被綁定到IsPredefined覆蓋,在一半的情況下工作。然後進行窗口的一般設置。 –