如何在不同的中心部分中隐藏应用栏按钮 Windows Phone

本文关键字:应用 隐藏 按钮 Phone Windows 心部 | 更新日期: 2023-09-27 17:56:55

我是C#的新手。当我继续小节时,应用栏仅在隐藏一个按钮的第 3 小节上保持不变。

HubPage.xaml

<Page.BottomAppBar>
    <CommandBar x:Name="mybar" ClosedDisplayMode="Minimal"  >
        <CommandBar.SecondaryCommands>
            <AppBarButton Label="setting" Click="AppBarButton_Click"/>
        </CommandBar.SecondaryCommands>
        <AppBarButton x:Uid="CALENDAR" Label="calendar" Click="AppBarButton_Click">
            <AppBarButton.Icon>
                <SymbolIcon x:Name="btnCalendar" Symbol="Calendar"/>
            </AppBarButton.Icon>
        </AppBarButton>
        <AppBarButton x:Name="btnLocation" x:Uid="MAP" Icon="MapPin" Label="location" Click="AppBarButton_Click"  />
    </CommandBar>
</Page.BottomAppBar>

HubPage.xaml.cs

private void Hub_SectionsInViewChanged(object sender, SectionsInViewChangedEventArgs e)
        {
            try
            {

                switch (MyHub.SectionsInView[0].Name)
                {
                    case "HubSection0":
                        btnCalendar.Visibility = Visibility.Visible;
                        btnLocation.Visibility = Visibility.Visible;
                        break;
                    case "HubSection1":
                        btnCalendar.Visibility = Visibility.Collapsed;
                        btnLocation.Visibility = Visibility.Visible;
                        break;
                    case "HubSection2":
                     btnCalendar.Visibility = Visibility.Collapsed;
                        btnLocation.Visibility = Visibility.Collapsed;
                        break;
                    case "HubSection3":
                          btnCalendar.Visibility = Visibility.Collapsed;
                        btnLocation.Visibility = Visibility.Collapsed;
                        break;
                    default:
                        return;
                }

            }
            finally
            {
            }
        }

如何在不同的中心部分中隐藏应用栏按钮 Windows Phone

如果我理解正确您的问题,您将 Name 属性设置在正确的位置。您应该为AppBarButton元素设置它,而不是为 SymbolIcon 设置它。我认为您的代码应该在此更改后工作。

CommandBar x:Name="mybar" ClosedDisplayMode="Minimal"  >
    <CommandBar.SecondaryCommands>
        <AppBarButton Label="setting" Click="AppBarButton_Click"/>
    </CommandBar.SecondaryCommands>
    <AppBarButton x:Uid="CALENDAR" x:Name="btnCalendar" Label="calendar" Click="AppBarButton_Click">
        <AppBarButton.Icon>
            <SymbolIcon  Symbol="Calendar"/>
        </AppBarButton.Icon>
    </AppBarButton>
    <AppBarButton x:Name="btnLocation" x:Uid="MAP" Icon="MapPin" Label="location" Click="AppBarButton_Click"  />
</CommandBar>