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/

相关文章:

javascript - 如何使用 Javascript 从 C# 代码设置的 div 内的 span 元素获取值

c# - 如何为位置记录定义额外的初始化逻辑?

c# - 从 DatePicker 和 TimePicker 控件创建 DateTime 对象

visual-studio-2012 - 在 WP8 设备上调试时 XAML 未更新

c# - 如何在 Entity Framework 核心中映射一对多可选递归关系

c# - 防止 Assembly.GetTypes() 加载依赖项

c# - 如何在 Windows Phone 7 设备上拍摄位图图像并另存为 JPEG 图像文件?

c# - 以编程方式启用 Windows Phone 7 应用程序中禁用的复选框

javascript - 让网络字体在 HTML5 Windows Phone 应用程序上工作?

windows-phone-8 - 添加辅助 Windows Phone 8 磁贴