我的Windows Phone应用中有两个应用栏按钮。我们称之为Button1和Button2。每个按钮都显示MenuFlyout
一些项目。问题很简单。点击Button1时,会出现相应的MenuFlyout
。如果在Button1的de MenuFlyout
打开时点击Button2,则应用程序崩溃时会出现"严重故障"例外。如果MenuFlyout
已打开,我在其外部点按,然后按下另一个MenuFlyout
按钮的按钮。当我点击另一个按钮时,我试图隐藏代码中的一个MenuFlyouts
,但仍然崩溃。有任何想法吗?提前谢谢。
答案 0 :(得分:0)
以下是第一个按钮的代码:
private void SelectButton_Click(object sender, RoutedEventArgs e)
{
if (menuFlyout != null)
{
menuFlyout.Items.Clear();
for (int i = 0; i < listSource.View.Count; i++)
{
flyoutItem = new MenuFlyoutItem();
flyoutItem.Text = this.listSource.View[i].ToString();
flyoutItem.FontSize = 16;
flyoutItem.FlowDirection = Windows.UI.Xaml.FlowDirection.LeftToRight;
flyoutItem.Click += flyoutItem_Click;
menuFlyout.Items.Add(flyoutItem);
}
menuFlyout.ShowAt(CmdBar);
}
}
这是另一个按钮:
private void FilterButton_Click(object sender, RoutedEventArgs e)
{
if (filterFlyout != null)
{
filterFlyout.Items.Clear();
for (int i = 0; i < _filterList.Count; i++)
{
FilterItem = new MenuFlyoutItem();
FilterItem.Text = _filterList[i];
FilterItem.FontSize = 16;
FilterItem.FlowDirection = Windows.UI.Xaml.FlowDirection.LeftToRight;
FilterItem.Click += FilterItem_Click;
filterFlyout.Items.Add(FilterItem);
}
filterFlyout.Items.Add(new MenuFlyoutItem());
filterFlyout.ShowAt(CmdBar);
}
}
这是按钮的xaml:
<Page.BottomAppBar>
<CommandBar x:Name="CmdBar" Background="#F0A30A" Foreground="Black">
<AppBarButton x:Uid="SelectButton" x:Name="SelectButton" Icon="Calendar" Label="day filter" Click="SelectButton_Click">
<AppBarButton.Flyout>
<MenuFlyout x:Name="menuFlyout">
<MenuFlyout.MenuFlyoutPresenterStyle>
<Style TargetType="MenuFlyoutPresenter">
<Setter Property="BorderBrush" Value="Blue"/>
<Setter Property="BorderThickness" Value="5"/>
</Style>
</MenuFlyout.MenuFlyoutPresenterStyle>
<MenuFlyoutItem x:Name="flyoutItem" Background="Black" Click="flyoutItem_Click" Margin="0,0,20.833,0"/>
</MenuFlyout>
</AppBarButton.Flyout>
</AppBarButton>
<AppBarButton x:Uid="FilterButton" x:Name="FilterButton" Icon="Clock" Label="time filter" Click="FilterButton_Click">
<MenuFlyout x:Name="filterFlyout">
<MenuFlyout.MenuFlyoutPresenterStyle>
<Style TargetType="MenuFlyoutPresenter">
<Setter Property="BorderBrush" Value="Blue"/>
<Setter Property="BorderThickness" Value="5"/>
</Style>
</MenuFlyout.MenuFlyoutPresenterStyle>
<MenuFlyoutItem x:Name="FilterItem" Click="FilterItem_Click" Margin="0,0,20.833,0"/>
</MenuFlyout>
</AppBarButton>
</CommandBar>
</Page.BottomAppBar>