我正在使用Windows手机上的应用程序。
我有一个TextBox的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 :(得分:0)
对我来说有用的是在启动FlyOut之前检查焦点状态
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);
}
}
}
如果TextBox处于编辑模式,则其FocusState
为Windows.UI.Xaml.FocusState.Pointer