动态创建应用栏

时间:2013-03-13 09:46:43

标签: cross-platform windows-phone-8 application-bar

我想创建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。从javainterface我已经使用给定的文本和图标创建了应用程序栏的实例。如何在网页上显示。

1 个答案:

答案 0 :(得分: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)
        {

        }
}