Application layout and basic navigation for Windows app development

Source: Internet
Author: User

A simple example looks at page layout and navigation

Start by creating a new project in the order of the previous blog post. Once you're done, open MainPage.xaml and start knocking on the code.

<Grid Background="{ThemeResource Applicationpagebackgroundthemebrush}"> <Grid. Rowdefinitions> <rowdefinition height=" the"/> <rowdefinition height="Auto"/> <rowdefinition height="*"/> </Grid. Rowdefinitions> <Grid. Columndefinitions> <columndefinition width=" the"/> <columndefinition width="6*"/> </Grid. Columndefinitions> <stackpanelGrid.Row="0" Grid. columnspan="2"orientation="Horizontal"> <textblockText="Page Layout"Foreground="Red" FontSize="Max"margin=" A"Width=" the"height="a"/> <textblockText="Basic Navigation"Foreground="Green" FontSize="Max"margin=" A"Width=" the"height="a"/> </StackPanel> <Grid Grid.Row="1" Grid.Column="0"> <ButtonContent="Navigate to Page two"Foreground="Blue" FontSize="very"margin="12,480,0,0"Name="Btngosecondpage"click="Btngosecondpage_click"/> </Grid> <canvasGrid.Row="1" Grid.Column="1"Horizontalalignment="Center"Verticalalignment="Center"> <RectangleFill="Blue"/> <RectangleFill="Yellow"height=" the"Width=" the"Canvas. Left=" the"Canvas.Top="a"/> <RectangleFill="White"height=" the"Width=" the"Canvas. Left=" the"Canvas.Top=" the"/> </Canvas> </Grid>

Here's how this code is written in turn.

1) First, the outermost grid control is divided into 3 rows and 2 columns. The height of the first row is 100 pixels, the height of the second row is automatic, and the so-called automatic is determined by the height of the control that is added in the future; the height of the third row is the rest, so it may not be clear what the asterisk means. Then look at the two columns in the cut, it's the width ratio is 4:6. It is clear that it is not necessarily necessary to add up to equal to 10, even if it is 4:100.

2) nested a StackPanel in the outermost grid and position it in the first row and across 2 columns. Grid is best at manipulating specific pixels, which can pinpoint any control to any point. The most important orientation attribute of StackPanel, however, is the arrangement of the controls in it, such as having two TextBlock controls arranged horizontally.

3) Here again nested the grid, there is a Button,foreground property is defined font color, fontsize property is defined font size. Here's a look at the margin property. We define the marin= "12,480,0,0" from left to right in the left, top, right, and bottom four directions away from the perimeter border.

The left margin is 12 in the designer and the top margin is not reflected, but it is indeed 480. Remember the previous auto, which is reflected here, because the bottom margin is 0, so the grid divider is just under the button. But why is the split line on the right not exactly on the right side of the button, because our previous 2 columns are cut to 4:6, rather than set auto.

4) The canvas is in the center of the grid control on its periphery, and horizontalaligment and verticalalignment represent the horizontal and vertical positions respectively. Canvas.Top and Canvas.Left indicate the distance from the top and bottom of the canvas, respectively.

5) Set a name for the button, and then knock down the click= "", it will appear as shown, this is directly by pressing the ENTER key can be directly named. Little tricks.

Then double click on the name of the click event and press the F12 key to automatically generate an event and jump to the C # file. The following code will make the page jump from mainpage to Secondpage.

privatevoidbtnGoSecondPage_Click(object sender, RoutedEventArgs e){      if (thisnull)  {     this.Frame.Navigate(typeof(SecondPage));  }}

Finish writing this code also don't hurry debugging, because have not created secondpage yet. Recommend to create a good after the best to add something to the inside, or jump past is the black vast piece still thought is a bug, add a basic TextBlock on it.

   Text="Second Page"FontSize=" 50"/>

Let me briefly introduce some of the things that are commonly used in VS, just for beginners. In the figure below, Box 1 allows the location of the designer and the XAML code to be swapped oh, I put the designer on the right side, but just for the sake of, the designer is still on the left side of the habit.

Box 2 allows designers and XAML code to be arranged and left and right, or not to display one of them. You can also set the grid alignment and the zoom ratio of the designer next to it.

There are too many things you can set in boxes 3 and 4, you can set the gradient color, you can set the Click event, you can also set the layout of the control, and so on.

App Bar Layout

Modern application on Windows I'm not used to it, but the application on WP8 I think the biggest difference with Android is its application bar, the following is how the application bar is done.

In document Outline (found in view, or press ctrl+w,u), there are Topappbar and Bottomappbar, respectively, on the top and bottom of the app bar. Click the right mouse button can quickly define AppBar and CommandBar, usually put AppBar on the upper end of the application is Topappbar, CommandBar placed in the lower end is Bottomappbar inside.

Perhaps a lot of people do not know, under the modern application, press the WIN+Z key can directly call out the application bar yo. Also note that unlike CommandBar, AppBar can contain only one child, typically defining a grid control and then nesting other controls inside the grid. An example of a appbar is posted below:

<page.topappbar>  <AppBar issticky="True">     <Grid>       <grid.columndefinitions>          <columndefinition/>          <columndefinition/>       </grid.columndefinitions>       <StackPanel Orientation="Horizontal">          <button Content="Main page" Width=" $" Height=" " Click=" Appbarbutton1_click "/>          <button Content="Second page" Width=" $" Height=" appbarbutton2_click" Click="/> "          <button  Content  =< Span class= "Hljs-value" > "third page"  width  = " " height  ="  " click  = "Appbarbutton3_click" />           <TextBlock Text="AppBar" Foreground="Red" FontSize= "Max" verticalalignment= "Center" Margin=" Width=" " />       </StackPanel>                          <searchbox grid.column= "1" Width=" Height=" " horizontalalignment=" right "/>    </Grid>  </AppBar></page.topappbar><page.bottomappbar>    <CommandBar>       <Appbarbutton Label="Refresh" Icon="Refresh"click = "Appbarbtn4_click"/>                    <Appbarbutton Label="Redo" Icon="Redo"click ="Appbarbtn5_click"/>                          <commandbar.secondarycommands>          <Appbarbutton Label= "add " Icon="Add" click =" Appbarbutton6_click "/>          <Appbarbutton Label="Delete " Icon="Delete" click ="Appbarbutton7_click"/>          <Appbarbutton Label= "edit" Icon="edit" click =" Appbarbutton8_click "/>       </commandbar.secondarycommands>                                        </CommandBar></page.bottomappbar>

But everyone should have found out, by default the application bar is hidden, if you want to be loaded when it is launched, then what to do? Very simply, it is good to define the IsOpen property directly in AppBar.

<CommandBar IsOpen="True">    <!-- --></CommandBar>

There are also sticky properties yo. That is, originally when the right-click out of the application bar, and then left-click the other location of the application bar will disappear, but if the Issticky property is true, you have to press a few more right-click to disappear.

<AppBar IsSticky="True">    <!-- --></AppBar>

In addition to defining these properties in XAML, we can also use functions in the background code, where I am using the Click event of the 2 button.

private   void  btnsetappbar_click  (object  sender, RoutedEventArgs e) {if  (this . Topappbar! = null ) {this .   Topappbar.issticky = true ; }}private  void   Btnsetappbar2_click  (object  sender, RoutedEventArgs e) {if  (bottomappbar.isopen ==false ) {this .    Bottomappbar.isopen = true ; }}

Since it is a general application, then WP side naturally is similar, but temporarily only bottomappbar but there is no topappbar it, the following is the system to generate code, and Windows on the same.

 < Page.bottomappbar ;  <commandbar  >
      <appbarbutton  Icon  = "Accept"  label  =  "Appbarbutton" />  < Appbarbutton  icon  = "Cancel"  label  =/>     </commandbar ;  </page.bottomappbar ;   

To learn more about the app bar, you can refer to the app bar in the next article.

Common Properties

Background: Background color
BorderBrush: Border Color
BorderThickness: Border Size

  <ButtonBackground="Red" BorderBrush="Blue" BorderThickness="5" Height="66" Width="153"/>

Clickmode: Click mode, specific 3 kinds: hover (Hover), press, release

Content: Contents
FontFamily: Font
FontSize: Font Size
Foreground: Font Color
FontStretch: How the font expands on the screen

Copyright NOTICE: This article is nomasp Couvant original article, if need reprint please contact oneself. Share the light of wisdom and protect intellectual property.

Application layout and basic navigation for Windows app development

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.