我想知道允许用户在 Windows 10 通用应用程序中将文本输入 MessageDialog 的最佳方法是什么(忘记密码系统)。从我所做的研究来看,使用 MessageDialog 似乎不可能做到这一点,但可以使用 ContentDialog 来完成。到目前为止我找到了this该网站粗略地解释了如何使用 ContentDialog,但不包括文本输入,以及 and this article on MSDN它确实显示了如何使用带有 ContentDialog 的文本框,但显示的方法对我来说似乎很复杂。
那么,有没有人知道执行此操作的任何更简单的方法,或者 MSDN 方法是最简单的方法吗?
感谢您的帮助
内森
最佳答案
是的,这是达到您要求的严格的最低要求:
页面:
using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace App1
{
public sealed partial class MainPage
{
public MainPage()
{
InitializeComponent();
Loaded += MainPage_Loaded;
}
private async void MainPage_Loaded(object sender, RoutedEventArgs e)
{
var dialog1 = new ContentDialog1();
var result = await dialog1.ShowAsync();
if (result == ContentDialogResult.Primary)
{
var text = dialog1.Text;
}
}
}
}
对话框(代码):
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace App1
{
public sealed partial class ContentDialog1 : ContentDialog
{
public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
"Text", typeof (string), typeof (ContentDialog1), new PropertyMetadata(default(string)));
public ContentDialog1()
{
InitializeComponent();
}
public string Text
{
get { return (string) GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
}
private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
}
private void ContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
}
}
}
对话框 (XAML):
<ContentDialog x:Class="App1.ContentDialog1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:App1"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:Name="ContentDialog"
Title="TITLE"
PrimaryButtonClick="ContentDialog_PrimaryButtonClick"
PrimaryButtonText="Button1"
SecondaryButtonClick="ContentDialog_SecondaryButtonClick"
SecondaryButtonText="Button2"
mc:Ignorable="d">
<Grid>
<TextBox Text="{Binding ElementName=ContentDialog, Path=Text, Mode=TwoWay}" />
</Grid>
</ContentDialog>
关于c# - 消息对话框中的文本输入?内容对话框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34538637/