2010-11-27 82 views
0

我有一個TextBox綁定到我的ViewModel。 TextBox的TextWrapping屬性綁定到我的View Model上名爲DocViewerWrapText的屬性。這是我的財產 - 忽略關於打開和關閉scollbar的位。Silverlight - 綁定到枚舉屬性

public string DocViewerWrapText 
{ 
    get { return _docViewerWrapText; } 
    set 
    { 
    _docViewerWrapText = value; 

    if (_docViewerWrapText == "Wrap") 
     ShowDocViewerHorizontalScrollBar = "Disabled"; 
    else ShowDocViewerHorizontalScrollBar = "Auto"; 
    NotifyPropertyChanged("ShowDocViewerHorizontalScrollBar"); 
    NotifyPropertyChanged("DocViewerWrapText"); 
    } 
} 

此代碼實際工作得很好,但它拋出第一個機會異常如下:

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中綁定枚舉的正確方法嗎?

感謝,

斯科特

回答

1

我發現這個問題。我需要改變propety getter/setter來返回正確的Enum類型。令我困惑的問題是布爾錯誤。事實證明,這是來自我在表單上切換文本換行值的按鈕。我有它綁定到相同的屬性,所以它不能從枚舉值轉換爲布爾值。

現在我只需要弄清楚如何轉換值。

-Scott