在我的一个 .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/