2015-12-30 4 views
8

मुझे आश्चर्य है कि किसी उपयोगकर्ता को Windows 10 सार्वभौमिक ऐप में MessageDialog में टेक्स्ट इनपुट करने का सबसे अच्छा तरीका क्या है। (पासवर्ड सिस्टम भूल गए)। मैंने जो शोध किया है, उससे मैसेजडियलोग के साथ ऐसा प्रतीत नहीं होता है लेकिन इसे ContentDialog के साथ पूरा किया जा सकता है। अब तक मुझे this साइट मिली है जो कंटेंटडिअलॉग का उपयोग करने के बारे में बताती है, लेकिन पाठ इनपुट के साथ नहीं, और and this article on MSDN जो दिखाती है कि ContentDialog के साथ टेक्स्टबॉक्स का उपयोग कैसे करें, लेकिन दिखाया गया तरीका मेरे लिए काफी जटिल लगता है।संदेश संवाद में पाठ इनपुट? ContentDialog?

तो, क्या किसी को ऐसा करने का कोई और सरल तरीका पता है या एमएसडीएन जिस तरह से सबसे आसान है?

किसी भी मदद के लिए धन्यवाद

नाथन

उत्तर

13

हाँ, यहाँ सख्त न्यूनतम प्राप्त करने के लिए आप के लिए क्या देख रहे हैं:

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

मैं ऐसे समारोह का उपयोग उपयोगकर्ता से पाठ का अनुरोध करने के:

private async Task<string> InputTextDialogAsync(string title) 
{ 
    TextBox inputTextBox = new TextBox(); 
    inputTextBox.AcceptsReturn = false; 
    inputTextBox.Height = 32; 
    ContentDialog dialog = new ContentDialog(); 
    dialog.Content = inputTextBox; 
    dialog.Title = title; 
    dialog.IsSecondaryButtonEnabled = true; 
    dialog.PrimaryButtonText = "Ok"; 
    dialog.SecondaryButtonText = "Cancel"; 
    if (await dialog.ShowAsync() == ContentDialogResult.Primary) 
     return inputTextBox.Text; 
    else 
     return ""; 
} 

और इसके उपयोग:

string text = await InputTextDialogAsync("Title"); 
+0

हे @ किबर्नेटिक, यह कमाल है! –

संबंधित मुद्दे