📜 ⬆️ ⬇️

Create an application for Windows Phone 7 from start to finish. Part 6. Support for landscape orientation, using controls

Previous part

In this part you will learn:

Support for portrait and landscape orientation


Portrait orientation is standard for Windows Phone applications. In order to implement support for landscape orientation, you will have to write additional code. To indicate that the application supports both portrait and landscape orientation, you must set the SupportedOrientations property to PortraitOrLandscape either in XAML or in code. Then you need to make sure that the contents of your application pages are displayed correctly in landscape orientation.

Interface Design Recommendation:
If the application supports text input, you must support landscape orientation due to the possibility of a hardware keyboard.
')
There are various ways to guarantee the correct display of content in both portrait and landscape orientation. The two main methods are scrolling and grid layout. These methods can be used alone or in combination with each other.

Scrolling uses the StackPanel control that is in the ScrollViewer control. Use this method if the content is displayed in a list or if the various controls follow each other on the page. StackPanel allows you to set the order of the child elements one by one, and the ScrollViewer control allows you to scroll through the contents of the StackPanel if the user interface elements do not fit on the screen.

Supports portrait and landscape orientation by scrolling
  1. Change the SupportedOrientations page property to PortraitOrLandscape.
  2. Replace standard Grid with ScrollViewer and StackPanel.
The second method, the grid, allows you to place user interface elements in a Grid control. If necessary, when orientation changes occur, you programmatically (programmatically) move elements to different cells of the grid.

Support for portrait and landscape orientation using the grid
  1. Change the SupportedOrientations page property to PortraitOrLandscape.
  2. Use the grid as a panel for content.
  3. If necessary, create an OrientationChanged event handler and add code to move the elements to the grid.
The Fuel Tracker application uses the grid, but also uses the ScrollViewer controls to ensure that all items in the list can be viewed by the user. The markup is fairly simple, so there is no need to make changes related to handling the OrientationChanged event. The following image shows the behavior of the application when changing orientation on the vehicle information page.

image

The controls in the application are used to display data and allow the user to interact with the application.

Selection of controls


You can use a large number of controls by simply dragging them from the toolbox onto the designer’s surface.

image

The following table will give you some guidance on which control you should use depending on your application requirements. The table shows Silverlight controls (such as Button and TextBox), as well as controls created specifically for Windows Phone (for example, Panorama and Pivot). There are other controls available in the Silverlight for Windows Phone Toolkit .
Application RequirementControl element
NavigationPhoneApplicationFrame
PhoneApplicationPage
ApplicationBarIconButton
ApplicationBarMenuItem
HyperlinkButton
MarkupBorder
Canvas
ContentControl
Grid
Panorama
Pivot
Stackpanel
Scrollviewer
VirtualizingStackPanel
Text displayTextblock
Text inputTextbox
Passwordbox
Displaying a list of itemsListbox
ButtonsButton
HyperlinkButton
The control to select from the listCheckbox
Radiobutton
Slider
Combobox *
Image displayImage
Work with cardsBing maps
Video displayMediaElement
HTML displayWebbrowser
ProgressProgressbar
Pop up messagesPopup
* Not styled for Metro design, but can be used if properly designed.

Performance Improvement Tip:
If you use the ProgressBar control in indeterminate mode, this may affect application performance. If you need an indeterminate progress bar, consider creating your own control.

Performance Improvement Tip:
When using demanding controls (such as Bing Maps or video) and if your application does not have enough memory, you can call the DeviceExtendedProperties.GetValue method to monitor memory usage.

The following image shows an example of using some controls on the summary page of the Fuel Tracker application. Notice that this page uses the Pivot control to expand the usable space.

image

Choose between Panorama and Pivot controls


Windows Phone has two special controls that effectively extend the markup area. The Panorama and Pivot controls provide the ability to horizontally navigate the content of the page, which allows the user to scroll and scale the content as needed. The Panorama control creates a panoramic view of the elements. The Pivot control provides an easy way to manage the views of large data sets in an application. The Pivot control can be used as a navigation interface to filter large sets or to switch between views.

On the summary page in the Fuel Tracker application, the Pivot control element is used, which allows the user to quickly switch between the information on the last refueling and the summary information on all of the refueling. Originally this information was located on one page. But such markup created a feeling of a strong page clutter, so two different views were paged into the Pivot control.

Design guidelines for Panorama and Pivot controls:

Using text entry controls


When adding controls for entering text into the application, you must leave space for the on-screen keyboard, also called the soft input panel (SIP). You must make sure that the keyboard does not hide the buttons or other navigation controls. One way to prevent this behavior is to place the navigation in the application bar.

To prevent user input errors, you must use the most appropriate on-screen keyboard by setting the InputScope property for the control. Two examples of InputScope values ​​are given in the following table.
KeyboardLayout
TelephoneNumberLayout with 12 numeric keys

image

TextStandard layout with features such as autocorrection and text suggestion (text suggestion)

image

Providing the correct keyboard layout will limit the possibility of the user making a mistake, but you must also implement user input validation.

Interface Design Recommendation:
If the application supports text input, you must support landscape orientation due to the possibility of a hardware keyboard.

Handling Control Events


A gesture event occurs when the user interacts with the screen, for example, by tapping or dragging his finger over it. Gesture processing is automatically included in all elements of the user interface and translates all gestures into standard events. For example, the Button control contains a Click event that occurs when a button is pressed. You create a method called an event handler to handle the event (to handle the event). You can create an event handler in the Properties window or in XAML code.

You can create an event handler using the Events tab of the Properties window. The Properties window lists all the events available for the selected control. The following image shows some of the events for Button.

image

To create an event handler with the default name, you can simply double-click the event name in the Properties window. An event handler is created and the code-behind file opens in the code editor. The following code fragment shows the Button event handler for the Button control.
private void PhotoButton_Click( object sender, RoutedEventArgs e) { } * This source code was highlighted with Source Code Highlighter .
  1. private void PhotoButton_Click( object sender, RoutedEventArgs e) { } * This source code was highlighted with Source Code Highlighter .
  2. private void PhotoButton_Click( object sender, RoutedEventArgs e) { } * This source code was highlighted with Source Code Highlighter .
  3. private void PhotoButton_Click( object sender, RoutedEventArgs e) { } * This source code was highlighted with Source Code Highlighter .
private void PhotoButton_Click( object sender, RoutedEventArgs e) { } * This source code was highlighted with Source Code Highlighter .
You can also create an event handler in XAML. In XAML edit mode, enter the name of the event you want to handle. When you start typing in XAML editing mode, the IntelliSense window appears. The following image shows how to define a Click event in XAML code.

image

Once you have defined an event, you can specify the name of the event handler or double-click <New Event Handler> in the IntelliSense window that appears. The following image shows the IntelliSense window, which appears to help you create a new event handler.

image

The following XAML snippet binds the Click event of a Button control to the PhotoButton_Click event handler .
  1. < Button Grid . Row = "2" Grid . ColumnSpan = "2"
  2. Content = "choose picture" Click = "PhotoButton_Click"
  3. HorizontalAlignment = "Center" VerticalAlignment = "Center" />
* This source code was highlighted with Source Code Highlighter .
Next part

Source: https://habr.com/ru/post/118050/


All Articles