UWP TextBox Wrapping: System.ArgumentException: 'The parameter is incorrect.

Posted by Blake on 3/24/2019


You're attempting to set the TextWrapping property on a UWP TextBox and you encouter the following exception.

Exception Message

System.ArgumentException: 'The parameter is incorrect.


C# (Not working):

private void MenuWordWrap_Click(object sender, RoutedEventArgs e)
    if (MenuWordWrap.IsChecked)
        TextBoxMain.TextWrapping = TextWrapping.WrapWholeWords;
        TextBoxMain.TextWrapping = TextWrapping.NoWrap;

Cause and Fix:

The issue in this case occurs because the TextBox control does not support the TextWrapping.WrapWholeWords enumeration. Not all controls that implement word wrapping implement all of the options and the TextBox is one of them. This is also true of the RichEditBox control.

To fix the error you will want to change "TextWrapping.WrapWholeWords" to the following:

TextBoxMain.TextWrapping = TextWrapping.Wrap;

Additional Info: