Settings the Content of a RichEditBox in CodeBehind works, but only if IsReadOnly="False".
As soon as I make it ReadOnly, I get the follwing exeption:
System.UnauthorizedAccessException
HResult=0x80070005
Message=Attempted to perform an unauthorized operation.
Source=WinRT.Runtime
StackTrace:
at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|38_0(Int32 hr)
at WinRT.ExceptionHelpers.ThrowExceptionForHR(Int32 hr)
at ABI.Microsoft.UI.Text.ITextDocumentMethods.SetText(IObjectReference _obj, TextSetOptions options, String value)
at Microsoft.UI.Text.RichEditTextDocument.SetText(TextSetOptions options, String value)
at RichEditBoxBug.MainWindow.RichEditBox_Loaded(Object sender, RoutedEventArgs e) in C:\Users\User\Documents\Programming\RichEditBoxBug\RichEditBoxBug\MainWindow.xaml.cs:line 26
at WinRT._EventSource_global__Microsoft_UI_Xaml_RoutedEventHandler.EventState.<GetEventInvoke>b__1_0(Object sender, RoutedEventArgs e)
at ABI.Microsoft.UI.Xaml.RoutedEventHandler.Do_Abi_Invoke(IntPtr thisPtr, IntPtr sender, IntPtr e)
Steps to reproduce the bug
Create a new packaged app
Add a RichEditBox
Set it's content in CodeBehind using richEditBox.Document.SetText(TextSetOptions.None, "Hello, World!");
Alternatively, the source-code can be found on my GitHub.
Expected behavior
Even according to the official documentation:
IsReadOnly gets or sets a value that indicates whether the user can change the text in the RichEditBox.
Therefore, I expect to be able to set the content of a ReadOnly RichEditBox programmatically. The only effect the ReadOnly state should have is preventing UserInput.
Screenshots
No response
NuGet package version
WinUI 3 - Windows App SDK 1.6.0: 1.6.240829007
Windows version
No response
Additional context
Windows Version: Windows 11 (23H2): Build 22631.4169
--> Please add this Version to the selectable Windows Versions
Describe the bug
Settings the Content of a RichEditBox in CodeBehind works, but only if IsReadOnly="False". As soon as I make it ReadOnly, I get the follwing exeption:
Steps to reproduce the bug
richEditBox.Document.SetText(TextSetOptions.None, "Hello, World!");
Alternatively, the source-code can be found on my GitHub.
Expected behavior
Even according to the official documentation:
IsReadOnly
gets or sets a value that indicates whether the user can change the text in the RichEditBox.Therefore, I expect to be able to set the content of a ReadOnly RichEditBox programmatically. The only effect the ReadOnly state should have is preventing UserInput.
Screenshots
No response
NuGet package version
WinUI 3 - Windows App SDK 1.6.0: 1.6.240829007
Windows version
No response
Additional context
Windows Version: Windows 11 (23H2): Build 22631.4169 --> Please add this Version to the selectable Windows Versions