c# - 消息对话框中的文本输入?内容对话框?

标签 c# xaml dialog windows-10 win-universal-app

我想知道允许用户在 Windows 10 通用应用程序中将文本输入 MessageDialog 的最佳方法是什么(忘记密码系统)。从我所做的研究来看,使用 MessageDialog 似乎不可能做到这一点,但可以使用 ContentDialog 来完成。到目前为止我找到了this该网站粗略地解释了如何使用 ContentDialog,但不包括文本输入,以及 and this article on MSDN它确实显示了如何使用带有 ContentDialog 的文本框,但显示的方法对我来说似乎很复杂。

那么,有没有人知道执行此操作的任何更简单的方法,或者 MSDN 方法是最简单的方法吗?

感谢您的帮助

内森

最佳答案

是的,这是达到您要求的严格的最低要求:

enter image description here

页面:

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/

相关文章:

c# - EF 中多对多连接的最佳实践

c# - 如何访问正在呈现的 ListBox 中的项目而不是其源数据?

c# - Xamarin Forms - 如何在 ListView 中显示/绑定(bind)列表?

wpf - DataGrid表显示额外的不必要的空行

c++ - MFC中获取最近文件列表的方法

java - 如何在 Dialog dismiss Android 上触发事件?

Angular Material 对话框 : How to update the injected data when they change in the parent component?

c# - 编译时未捕获转换错误

c# - 如何将 DataContext 设置为多个类?

c# - REngine' 不包含 'SetDllDirectory' 的定义,'RDotNet