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
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