简体   繁体   中英

How to use RichEditBox in Visual Basic to save the file?

I want to save whatever is being typed in RichEditBox. Below is my example. I was able to successfully with TextBox by using "mytext.Text" but there is no such option that I could see of RichEditBox.

 Private Async Function Button_Click(sender As Object, e As RoutedEventArgs) As Task
    Dim savePicker As New FileSavePicker
    savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary
    ' Dropdown of file types the user can save the file as

    savePicker.FileTypeChoices.Add(".txt", New List(Of String) From {".txt"})

    ' Default file name if the user does not type one in or select a file to replace
    savePicker.SuggestedFileName = "New Document"
    Dim file As StorageFile = Await savePicker.PickSaveFileAsync
    If file IsNot Nothing Then
        ' Prevent updates to the remote version of the file until we finish making changes and call CompleteUpdatesAsync

        CachedFileManager.DeferUpdates(file)
        ' Write to file
        Await FileIO.WriteTextAsync(file, txtfile.)
        ' Let Windows know that we are finished changing the file so the other app can update the remote version of the file.
        ' Completing updates may require windows to ask for user input
        Dim status As FileUpdateStatus = Await CachedFileManager.CompleteUpdatesAsync(file)
    End If

End Function

Assuming a Windows.UI.Xaml.Controls.RichEditBox , you can retrieve the text with the GetText method of the control's Document property. You can also write the document directly to a stream with the SaveToStream method of the Document property.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM