0

我的 Windows Phone 应用程序中有一个应用程序栏

  <phone:PhoneApplicationPage.ApplicationBar>
    <shell:ApplicationBar>
        <shell:ApplicationBarIconButton x:Name="Refresh" IconUri="Images/appbar.sync.rest.png" Text="Actualiser" Click="ApplicationBarIconButton_Click" />
        <shell:ApplicationBarIconButton x:Name="Favorite"  IconUri="Images/appbar.favs.addto.rest.png" Text="Favorite" Click="ApplicationBarIconButton_Click_1" />
    </shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>

当我点击时,我需要将可见性设置<shell:ApplicationBarIconButton x:Name="Favorite" IconUri="Images/appbar.favs.addto.rest.png" Text="Favorite" Click="ApplicationBarIconButton_Click_1" /> 为 false

怎么能这样??

此致

4

2 回答 2

3

您不能将应用栏中单个按钮的可见性设置为折叠状态。但是您可以enable/disable通过使用IsEnabled属性或从后面的代码中动态删除它们ApplicationBar.Buttons.Remove(object)并传递您在单击事件时收到的按钮对象。我想它应该工作。

于 2012-11-08T10:54:46.153 回答
0

您需要做的是在您的应用程序中有 2 个不同的 AppBars - 第一个带有 2 ApplicationBarIconButtons(刷新和收藏),第二个只有 Refresh ApplicationBarIconButton

在您的EventHandlerfor 中ApplicationBarIconButton_Click_1,您可以更改AppBar当前向用户显示的内容。

像这样的工作...

ApplicationBar appBar1 = new ApplicationBar();
ApplicationBarIconButton refreshIcon = new ApplicationBarIconButton();
refreshIcon.text = "Refresh";
refreshIcon.Click += new EventHandler(Refresh_Click);
appBar1.add(refreshIcon);

ApplicationBarIconButton favIcon = new ApplicationBarIconButton();
favIcon.text = "Refresh";
favIcon.Click += new EventHandler(Fav_Click);
appBar1.add(favIcon);

ApplicationBar appBar2 = new ApplicationBar();
ApplicationBarIconButton refreshIcon2 = new ApplicationBarIconButton();
refreshIcon2.text = "Refresh";
refreshIcon2.Click += new EventHandler(Refresh_Click);
appBar2.add(refreshIcon2);

ApplicationBar = appBar1; // Assign the AppBar with both buttons as the default.

然后在EventHandlerfor 中Fav_Click,写

ApplicationBar = appBar2; // This will make the AppBar with only "Refresh" button visible giving the impression that the Favorite button has been made invisible.
于 2012-11-08T23:33:19.027 回答