2013-01-24 41 views
0

我在我的Windows Phone應用程序,其中包含2 appbariconbutton的應用程序任務欄:開關ApplicationBarIcon iconuri

<phone:PhoneApplicationPage.ApplicationBar> 
    <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True"> 
     <shell:ApplicationBarIconButton x:Name="appbar_button1" IconUri="/Images/appbar_im1_selected.png" Text="im1" Click="appbar_button1_Click" /> 
     <shell:ApplicationBarIconButton x:Name="appbar_button2" IconUri="/Images/appbar_im2.png" Text="im2" Click="appbar_button2_Click" /> 

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

我需要的是改變2 appbariconbutton的iconUri這樣

private void appbar_button1_Click(object sender, EventArgs e) 
     { 
      //Switch the iconuri of appbar_button1 from /Images/appbar_im1_selected.png to /Images/appbar_im1.png 
//Switch the iconuri of appbar_button2 from /Images/appbar_im2.png to /Images/appbar_im1_selected.png 
     } 

如何可以這樣做嗎?

回答

2

只要改變圖標的​​IconUri

private void appbar_button1_Click(object sender, EventArgs e) 
{ 
    ((ApplicationBarIconButton)this.ApplicationBar.Buttons[0]).IconUri = new Uri("/Images/appbar_im1.png", UriKind.Relative); 
    ((ApplicationBarIconButton)this.ApplicationBar.Buttons[1]).IconUri = new Uri("/Images/appbar_im1_selected.png", UriKind.Relative); 
}