我有一个绑定到ViewModel的文本框。文本框的TextWrapping属性绑定到我的视图模型上名为DocViewerWrapText的属性。这是我的财产-忽略关于打开和关闭scollbar的细节。
public string DocViewerWrapText
{
get { return _docViewerWrapText; }
set
{
_docViewerWrapText = value;
if (_docViewerWrapText == "Wrap")
ShowDocViewerHorizontalScrollBar = "Disabled";
else ShowDocViewerHorizontalScrollBar = "Auto";
NotifyPropertyChanged("ShowDocViewerHorizontalScrollBar");
NotifyPropertyChanged("DocViewerWrapText");
}
}
这段代码实际上工作得很好,但它抛出了一个First-Chance异常,如下所示:
System.Windows.Data Error: 'MS.Internal.Data.DynamicValueConverter' converter failed to convert value 'NoWrap' (type 'System.String'); BindingExpression: Path='DocViewerWrapText' DataItem='UnityEca.ViewModels.HomeViewModel' (HashCode=41697354); target element is 'Telerik.Windows.Controls.RadToggleButton' (Name='docViewerWrapText'); target property is 'IsChecked' (type 'System.Nullable`1[System.Boolean]').. System.FormatException: String was not recognized as a valid Boolean.
我试过将属性转换为布尔值,但得到的错误类型相同。我还查看了TextWrapping枚举的实际枚举。值是1和2,所以我不知道如何在这里使用布尔值。
有人能告诉我在XAML中绑定到这样的枚举的正确方法吗?
谢谢,
-斯科特