簡單的文本編輯器UWP TextBox控件給人意想不到的效果
隨着文本框AcceptsReturn屬性檢查文本框的內容多保存到一個文本文件,結果寫在只有在記事本中打開一行的所有文本。在UWP TextBox控件中加載文件時,它打開正常。我沒有舊的WPF TextBox控件的這個問題。
我的程序有兩個按鈕,打開並保存。之間有文本框。
using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Popups;
using Windows.Storage.Pickers;
using Windows.Storage;
// ...
StorageFile selectedFile;
private async void openFileButton_Click(object sender, RoutedEventArgs e)
{
contentsTextBox.Text = string.Empty;
addressText.Text = string.Empty;
selectedFile = null;
FileOpenPicker openDialog = new FileOpenPicker();
openDialog.FileTypeFilter.Add("*");
selectedFile = await openDialog.PickSingleFileAsync();
if (selectedFile != null)
{
addressText.Text = selectedFile.Path;
try
{
contentsTextBox.Text = await FileIO.ReadTextAsync(selectedFile);
}
catch (ArgumentOutOfRangeException) { } // In case file is empty
}
}
private async void saveFileButton_Click(object sender, RoutedEventArgs e)
{
if (selectedFile != null)
{
await FileIO.WriteTextAsync(selectedFile, contentsTextBox.Text);
await new MessageDialog("Changes saved!").ShowAsync();
}
}
箱子是否也設置爲多行?在Win32中,你需要兩個。 –
文本框屬性窗口中沒有多行選項 – Mooncat
openDialog.FileTypeFilter.Add(「*」);打破 – lindexi