c# - 尝试更改 AppBar 项的 IsEnabled 属性时出现 NullReferenceException 错误

标签 c# windows-phone-7 windows-phone-8 tiles

在我的一个 .xaml 页面上,我有一个带有几个图标的应用栏。

其中一个图标将页面固定到“开始”,因此当它被固定时,我想将该图标的 IsEnabled 属性更改为 false。

但是我得到了这个奇怪的错误;调用此过程时,如标题中所述。

这是代码:

if (Tile == null) { }
else { appBarPin.IsEnabled = false; }

有任何想法吗?

最佳答案

应用程序栏的行为与其他 UI 元素不同。来自 App bar for Windows Phone :

The app bar doesn’t support some common features of controls, such as data-binding. As a result, you can’t change the icon button and menu item text by using Name properties that you set in XAML.



如果要更改 appbar 项的属性,请按以下方式进行:
ApplicationBarIconButton button = (ApplicationBarIconButton)ApplicationBar.Buttons[0];
button.IsEnabbled = false;

替换 0与按钮的索引。 IE。如果按钮是应用栏的第二个按钮,则索引将为 1。

How to change app bar icon buttons and menu items dynamically for Windows Phone 中查看更多信息

关于c# - 尝试更改 AppBar 项的 IsEnabled 属性时出现 NullReferenceException 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17866892/

相关文章:

c# - Xamarin iOS 错误 : Can not resolve reference

c# - 执行web服务方法并立即返回

c# - C# 原始数据类型是该语言的一部分吗?

c# - EntityFramework 存储库模板 - 如何在模板类中编写 GetByID lambda?

c# - 如何访问行和列内的元素

windows-phone-7 - 从 wp7 获取国家列表

windows-phone-8 - Windows Phone 8 自定义动态磁贴

c# - 使用诺基亚 map 的 Windows phone 8 GeoFencing

c# - WP7 相当于 EmptyDataTemplate?

javascript - Windows Phone 8 IE scrollTo不起作用