2017-11-21 9 views
0

コンテンツボックスでピボットアイテム内にpasswordboxを実装しようとしています。 私はpointerpressedを使用してpivotitemをクリックすると、パスワードのダイアログを起動するのに適しているかどうか確認したいですか? また、ピボットアイテムがクリックされると、イベントをどのように処理しますか。おかげさまで Windows IoT UWPコンテンツボックスにPasswordBoxを持つピボットアイテム

XAML;

Title="Login" 
PrimaryButtonText="OK" 
SecondaryButtonText="Cancel" 
PrimaryButtonClick="ContentDialog_PrimaryButtonClick" 
SecondaryButtonClick="ContentDialog_SecondaryButtonClick"> 

<Grid> 
    <StackPanel> 
     <PasswordBox x:Name="passwordBox" Width="300" Height="30" PlaceholderText="Enter password" PasswordChar="*" 
        PasswordChanged="PasswordBox_PasswordChanged"/> 
     <TextBlock x:Name="statusText" Margin="3,10,2,10" Height="22"/> 
    </StackPanel> 
</Grid> 

アップデート - 24-11-2017 私は、これが最善のが私のパスワードを確認することだったあるかどうかわからないです。 content dialogが終了した後もわかります。どこでXAMLコードをさらに展開すればよいですか? 希望私はここで私のシナリオを明確に表現しています。ありがとう。

<PivotItem Header="Settings" x:Name="settings" PointerPressed="settings_PointerPressed" > 
       <ContentDialog Title="Login" x:Name="loginDialog" 
           PrimaryButtonText="OK" 
           SecondaryButtonText="Cancel" 
           PrimaryButtonClick="OK_PrimaryButtonClick" 
           SecondaryButtonClick="Cancel_SecondaryButtonClick"> 
        <Grid> 
         <StackPanel> 
          <PasswordBox x:Name="passwordBox" Width="300" Height="40" PlaceholderText="Enter PIN" PasswordChar="*" 
             PasswordChanged="passwordBox_PasswordChanged" IsPasswordRevealButtonEnabled="False"> 
           <PasswordBox.InputScope> 
            <InputScope> 
             <InputScope.Names> 
              <InputScopeName NameValue="NumericPin"/> 
             </InputScope.Names> 
            </InputScope> 
           </PasswordBox.InputScope> 
          </PasswordBox> 
          <TextBlock x:Name="passwordStatus" Margin="3,10,2,10" Height="22"/> 
         </StackPanel> 
        </Grid> 
       </ContentDialog> 

       </PivotItem> 

     private async void settings_PointerPressed(object sender, PointerRoutedEventArgs e) 
    { 
     if(isPasswordGranted==false) 
     { 
      await loginDialog.ShowAsync(); 

      //PasswordBox passwordBox = new PasswordBox(); 
      //passwordBox.Header = "Enter password"; 

      InputScope scope = new InputScope(); 
      InputScopeName scopeName = new InputScopeName(); 
      scopeName.NameValue = InputScopeNameValue.NumericPin; //default = Password 
      scope.Names.Add(scopeName); 
      passwordBox.InputScope = scope; 
     } 


    } 

    private void OK_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) 
    { 
     if (passwordBox.Password == pinNumber) 
     { 
      passwordStatus.Text = "Password Granted!"; 
      isPasswordGranted = true; 
     } 
     else pivot.SelectedItem = home; 
    } 

    private void Cancel_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) 
    { 
     pivot.SelectedItem = home; 
    } 

答えて

1

はい、PointerPressedイベントを使用してパスワードのダイアログをトリガーするのに適しています。ポインターがPivotItem要素の境界領域内のプレスアクション(タッチダウン、マウスボタンダウン、ペンダウン、またはタッチパッドボタンダウンなど)を示すとき、このイベントメソッドが呼び出されます。

*の.xaml

<PivotItem Header="PivotItem Header - 1" PointerPressed="PivotItem_PointerPressed"> 
     <ContentDialog Title="Login" x:Name="contentDialogForPwd" 
       PrimaryButtonText="OK" 
       SecondaryButtonText="Cancel" 
       PrimaryButtonClick="ContentDialog_PrimaryButtonClick" 
       SecondaryButtonClick="ContentDialog_SecondaryButtonClick"> 

      <Grid> 
       <StackPanel> 
        <PasswordBox x:Name="passwordBox" Width="300" Height="30" PlaceholderText="Enter password" PasswordChar="*" 
       PasswordChanged="passwordBox_PasswordChanged"/> 
        <TextBlock x:Name="statusText" Margin="3,10,2,10" Height="22"/> 
       </StackPanel> 
      </Grid> 
     </ContentDialog> 
    </PivotItem>  

* .CS

private async void PivotItem_PointerPressed(object sender, PointerRoutedEventArgs e) 
    { 
     ContentDialogResult result = await contentDialogForPwd.ShowAsync(); 
     if(result == ContentDialogResult.Primary) 
     { 
      //To do something when clicking Primary button 
     } 
     else if (result == ContentDialogResult.Secondary) 
     { 
      //To do something when clicking Secondary button 
     }  
    } 
+0

ありがとう:コードは、以下を参照してください。パスワードボックスの仮想キーボードを有効にする方法はありますか?パスワードを受け入れると、ピボットアイテムをクリックしてもパスワードダイアログが再度表示されないようにするにはどうすればよいですか? – mylim

+0

** Device Portal **を使用して仮想キーボードを有効にすることができます(デバイス設定 - >オンスクリーンキーボード、チェックボックスをオンにします)。そして、パスワードダイアログを表示する必要がある時を示すフラグとして、変数 を設定することができます。 –

+0

ありがとうございます。私はパスワード 'content dialog'に追加の質問があります。私のパスワード' content dialog'は 'pivotitem'にあるので、' content dialog'が閉じた後、同じ 'pivotitem'でコードを展開するには? – mylim

関連する問題