简单的文本编辑器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