0
votes

I'm working on a Windows Phone App which uses the clipboard to exchange large texts by using the TextBox Pasting-Function of the OnScreen-Keyboard.

For me it looks like if there is a 32000 chars limit.

PasteTextBox.TextChanged += new TextChangedEventHandler(OnTextChanged);
private void OnTextChanged(object sender, TextChangedEventArgs e)
{
    CounterTextBlock.Text = PasteTextBox.Text.Length.ToString();
}

The code crashes if I'm pasting more than 32000 chars into the TextBox. TextBox.MaxLength is 0 (unlimited), increasing it didn't help.

Is this a technical limit or what can I do to prevent the crash?

Update: Maybe I have explained bad. I try again: There can be a large amount of text in the clipboard, which I want to import into the app. Clipboard.GetText is blocked on Windows-Phone, so I go the detour over the textbox to get the text. It works fine if clipboard text is <= 32000.

Update2: Hm, I'm not sure what's going on after @f14shm4n wrote it would work. Here my full example:

    private void ApplicationPage_Loaded(object sender, RoutedEventArgs e)
    {
        Clipboard.SetText("... Long Text with 1000 Chars ...");
        PasteTextBox.TextChanged += new TextChangedEventHandler(OnTextChanged);
    }

    private void OnTextChanged(object sender, TextChangedEventArgs e)
    {
        CounterTextBlock.Text = PasteTextBox.Text.Length.ToString();
    }

Now if I run the app and click the textbox the OnScreen-Display comes up with the paste symbol. I can repeatedly press the paste-button until counter shows 32000. One more click on the paste symbol crashes the app. It happens in the Visual Studio emulator and also on my real Windows Phone. I believe it must be a glitch in the pasting mechanism but I could also be completely wrong. Is it really only me?

Update3: After some tests it looks now like a "Umlaut" problem (äöü are german Umlauts). If I add following line to the code of @f14shm4n before(!) his Append-Loop his code will crash too:

    sb.Append("ö");

Strange thing is it does not crash with "ä" or "ü", only with "ö". It also does not crash if I move this line after(!) the Append-Loop. Can other people confirm this behaviour or is it again only me?

Update 4: Bug message System.Exception was unhandled Message: An unhandled exception of type 'System.Exception' occurred in System.Windows.ni.dll Additional information: Error HRESULT E_FAIL has been returned from a call to a COM component.

-$exception {System.Exception: Error HRESULT E_FAIL has been returned from a call to a COM component. at MS.Internal.XcpImports.CheckHResult(UInt32 hr) at MS.Internal.XcpImports.TextBox_GetRectFromCharacterIndex(DependencyObject sender, UInt32 charIndex, Boolean trailingEdge) at System.Windows.Controls.TextBox.GetRectFromCharacterIndex(Int32 charIndex, Boolean trailingEdge) at System.Windows.Controls.SipHelper.AdjustFrame(FrameworkElement element, Double bottomMargin, Double& stillObscured) at System.Windows.Controls.SipHelper.SelectionChanged(Object sender, RoutedEventArgs e) at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args) at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)} System.Exception

1
If the textbox has no limit, maybe your problem came cause you're doing it at once. Why don't you try to split the code to put the text inside it in two steps and tell us?Btc Sources
@BtcSources: if that's the solution, it must be done by the user, not by the programmer.Thomas Weller
Is the limit 32000 or 32767 (working) / 32768 (not working)?Thomas Weller
Can you clarify what "code crashes" means? Do you get an exception?Ron Beyer
I tested your code with 38000+ chars and it work for me. No crash, but any actions with UI and this long text will be very slowly. And bearing in mind the fact that the TextBox size can not be more than 2048x2048 pixels, TextBox can't display any very long text.f14shm4n

1 Answers

1
votes

What I'm do:

    private void b1_Click(object sender, RoutedEventArgs e)
    {
        int count = 10000;

        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < count; i++)
        {
            sb.Append(i.ToString());
        }

        DBG.WriteLine("SBLength: " + sb.Length);
        Clipboard.SetText(sb.ToString());
    }

1) This code generated long text with length = 38890 chars and set it text to Clipboard (as in your code).

2) Then I tap on editable area in TextBox, opening OnScreen-keyboard.

3) Tap on past button icon.

Result: All text in clipboard pasted in first TextBox, when fired TextChanged event, second TextBox(or TextBlock nevermind) update Text property and show 38890. This is write ? :)