2013-03-13 90 views
0

我想創建Application Bar dynamically in Windows Phone 8。我用下面的代碼在appbar.cs文件動態創建應用程序欄

class AppBar 
    { 
    public AppBar() 
    { 
     ApplicationBar appbar; 
      this.appbar = new ApplicationBar(); 
      this.appbar.IsVisible = true; 
      this.appbar.Opacity = 1; 
      this.appbar.Mode = ApplicationBarMode.Minimized; 
      ApplicationBarIconButton appButon = new ApplicationBarIconButton(); 
      appButon.IconUri = new Uri("/images/show.png", UriKind.Relative); 
      appButon.Text = "Show"; 
      this.appbar.Buttons.Add(appButon); 
      appButon.Click += appButon_Click; 

     } 
    } 

     void appButon_Click(object sender, EventArgs e) 
     { 

     } 
} 

創建應用程序欄,如果我有創建AppBar類,那麼所有的方法叫的實例,但我無法看到應用程序欄。我給了request to create the appbar from webview。在java接口中,我創建了具有給定文本和圖標的應用程序欄實例。如何在網頁中顯示此內容。

回答

0

我解決了我的應用程序欄問題。 Added my application bar with parent element(PhoneApplicationPage)

class AppBar 
    { 
    public AppBar() 
    { 
     ApplicationBar appbar; 
     PhoneApplicationPage parentpage = (Application.Current.RootVisual as ContentControl).Content as PhoneApplicationPage; 
      parentpage.ApplicationBar = new ApplicationBar();   
      appbar = parentpage.ApplicationBar; 
      appbar.IsVisible = true; 
      appbar.Opacity = 1; 
      appbar.Mode = ApplicationBarMode.Minimized; 
      ApplicationBarIconButton appButon = new ApplicationBarIconButton(); 
      appButon.IconUri = new Uri("/images/show.png", UriKind.Relative); 
      appButon.Text = "Show"; 
      appbar.Buttons.Add(appButon); 
      appButon.Click += appButon_Click; 

     } 
    } 

     void appButon_Click(object sender, EventArgs e) 
     { 

     } 
}