Text input in message dialog? ContentDialog?

后端 未结 3 2047
说谎
说谎 2021-02-13 19:17

I am wondering what is the best way to allow a user to input text into a MessageDialog in a Windows 10 universal app.(Forgot password system). From the research I\'ve done this

3条回答
  •  既然无缘
    2021-02-13 20:24

    Yes, here's the strict minimum to achieve what you're looking for :

    Page :

    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;
                }
            }
        }
    }
    

    Dialog (code) :

    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)
            {
            }
        }
    }
    

    Dialog (XAML) :

    
    
        
            
        
    
    

提交回复
热议问题