2014-03-05 170 views
1

我想操纵我的应用程序中的按钮启用和禁用proprety,但每次我得到一个异常告诉我系统访问冲突!这是怎么回事就访问冲突异常applicationbar

<phone:PhoneApplicationPage.ApplicationBar > 
    <shell:ApplicationBar IsMenuEnabled="True" BackgroundColor="#989898" ForegroundColor="White"> 
     <shell:ApplicationBarIconButton IconUri="/Images/APPBAR/Mes-infos-personnelles copie.png" x:Name="Profile_Button" IsEnabled="True" Text="Profile" /> 

     <shell:ApplicationBar.MenuItems> 
      <shell:ApplicationBarMenuItem Text="Box" /> 

     </shell:ApplicationBar.MenuItems> 

    </shell:ApplicationBar> 
</phone:PhoneApplicationPage.ApplicationBar> 

,并在我的代码后面的任何想法:

Profile_Button.IsEnabled = false;//exception here 
+0

发布一些代码以及.. –

回答

0

试试这个

((ApplicationBarIconButton) ApplicationBar.Buttons[0]).IsEnabled = false; // disables Profile_Button button 

//禁止从应用程序栏的所有按钮和菜单项

foreach (var button in ApplicationBar.Buttons) 
     { 
      ((ApplicationBarIconButton) button).IsEnabled = false; 
     } 

     //To prevent the menu from opening you have to use this code: 
     ApplicationBar.IsMenuEnabled = false;