J'ai un TextBox qui est lié à mon ViewModel. La propriété TextWrapping de TextBox est liée à une propriété sur mon modèle View DocViewerWrapText. Voici ma propriété - ignorer les bits sur l'activation et la désactivation du scollbar.Silverlight - Liaison aux propriétés Enum
public string DocViewerWrapText
{
get { return _docViewerWrapText; }
set
{
_docViewerWrapText = value;
if (_docViewerWrapText == "Wrap")
ShowDocViewerHorizontalScrollBar = "Disabled";
else ShowDocViewerHorizontalScrollBar = "Auto";
NotifyPropertyChanged("ShowDocViewerHorizontalScrollBar");
NotifyPropertyChanged("DocViewerWrapText");
}
}
Ce code fonctionne en fait très bien, mais il jette une première chance exception comme suit:
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.
J'ai essayé de convertir ma propriété à un booléen, mais j'obtenir le même type d'erreur . J'ai aussi regardé l'enum pour l'enumération TextWrapping. Les valeurs sont 1 et 2, donc je ne vois pas comment je pourrais utiliser un booléen ici de toute façon. Est-ce que quelqu'un peut me dire la bonne façon de se lier à des énumérations comme celle-ci dans XAML?
Merci,
-Scott