为什么我的ApplicationBarIconButton为null?
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="True" x:Name="appBar">
<shell:ApplicationBarIconButton x:Name="appbarSave"
IconUri="/Icons/appbar.save.rest.png Text="Save" IsEnabled="False"
Click="appbarSave_Click" />
</shell:Application Bar>
</phone:PhoneApplicationPage.ApplicationBar>
appBarSave对象为空,尝试使用以下代码:
Initialize Component();
appbarSave.IsEnabled = true;
导致 NullReferenceException 异常。该对象仅在点击事件中起作用(如果启用):
private void appbarSave_Click(object sender, EventArgs e)
{
ApplicationBarIconButton button = (ApplicationBarIconButton)sender;
button.IsEnabled = false;
}
我希望能够在开始时将保存按钮设置为禁用,稍后再启用它。