2014-11-04 30 views
1

我正在開發Windows Phone上的應用程序。如何在編輯模式下禁用TextBox MenuFlyout

我有一個文本框的MenuFlyout。如何在TextBox處於編輯模式時禁用MenuFlyout? (即用戶點擊它並且鍵盤已啓動)? 當用戶完成編輯時(當鍵盤關閉時)重新啓用它。

這是我的XAML代碼:

<TextBox x:Name="ListItem" Holding="OnHolding"> 
          <FlyoutBase.AttachedFlyout> 
           <MenuFlyout> 
            <MenuFlyoutItem x:Uid="DeleteListItemMenuItem" 
               Command="{Binding MenuCommand}" 
               CommandParameter="{Binding}" /> 
           </MenuFlyout> 
          </FlyoutBase.AttachedFlyout> 
         </TextBox> 

這是我的代碼背後:

private void OnListItemHolding(object sender, HoldingRoutedEventArgs args) 
     { 
      TextBox textBox = sender as TextBox; 
      if (textBox == null) return; 

      // this event is fired multiple times. We do not want to show the menu twice 
      if (args.HoldingState != HoldingState.Started) { 
       return; 
      } 


      // If the menu was attached properly, we just need to call this handy method 
      FlyoutBase.ShowAttachedFlyout(textBox); 
     } 
+0

顯示一些代碼,請。感興趣的是你如何能夠管理這一點。我用'FlyoutBase.AttachedFlyout'做的方式沒有任何問題。 – 2014-11-05 05:26:29

回答

0

什麼工作對我來說是啓動彈出像這樣

前檢查焦點狀態
private void TextBox_Holding(object sender, HoldingRoutedEventArgs e) 
{   
    if (e.HoldingState == Windows.UI.Input.HoldingState.Completed) 
    { 
     TextBox tb = sender as TextBox; 
     if (tb.FocusState == Windows.UI.Xaml.FocusState.Unfocused) 
     { 
      FlyoutBase.ShowAttachedFlyout((FrameworkElement)sender); 
     } 
    }   
} 

如果TextB牛是在編輯模式下,它具有Windows.UI.Xaml.FocusState.PointerFocusState

相關問題