简体   繁体   中英

Proper way of building application bar in WP7

I'am doing localized application in WP7 so I make my app bar in code. The problem appears when I have some form (registration, login etc.). In Blend everything looks all right, but when I emulate it on device my gird with textboxes, textblocks is totally different (sometimes they are on each other)

My solution is to build empty app bar in Blend (PhoneApplicationPage -> New (Common Properties)) and then make new one in code like that:

private void BuildApplicationBar()
        {
            // Set the page's ApplicationBar to a new instance of ApplicationBar.
            ApplicationBar = new ApplicationBar();

            // Create a new button and set the text value to the localized string from AppResources.
            ApplicationBarIconButton OkAppBarButton = new ApplicationBarIconButton(new Uri("icons/ok.png", UriKind.Relative));
            OkAppBarButton.Text = AppResource.OkAppBarButton;
            ApplicationBar.Buttons.Add(OkAppBarButton);
            OkAppBarButton.Click += new EventHandler(OkAppBarButton_Click);

            ApplicationBarIconButton CancelAppBarButton = new ApplicationBarIconButton(new Uri("icons/cancel.png", UriKind.Relative));
            CancelAppBarButton.Text = AppResource.CancelAppBarButton;
            ApplicationBar.Buttons.Add(CancelAppBarButton);
            CancelAppBarButton.Click += new EventHandler(CancelAppBarButton_Click);
        }

Works good, but I wanted just to be sure is that the proper way to handle with that?

@dargod. There are a number of frameworks around to help build and bind the appbar. The key problem with the app bar that many people have complained about is that fact that the bar does not support commanding out of the box, so does not lend itself to MVVM.

Here are some links that may help

AppBarUtils

Bindable App bar

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM