Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > Windows Store Apps > Windows Store and Controls (C#) > AppBar : TopAppBar / BottomAppBar บน Windows Store Apps (C#)



Clound SSD Virtual Server

AppBar : TopAppBar / BottomAppBar บน Windows Store Apps (C#)

รู้จักกับ AppBar : TopAppBar / BottomAppBar บน Windows Store Apps (C#) สำหรับ AppBar บน Windows Store Apps คือ Application Bar ของโปรแกรมซึ่งจะไว้สร้างเป็น Navigation หรือ Command ซึ่ง AppBar เราจะเห็นมีอยู่ 2 ส่วนด้วยกันคือ TopAppBar (แสดงด้านบนหน้าจอ App) และ BottomAppBar (แสดงด้านล่างของ Apps) โดยการทำงาของ AppBar สามารถเรียกให้โชว์และแสดงได้ตลอดเวลา เหมาะสำหรับสร้างเป็น Navigation และเมนู Function คำสั่ง Command ต่าง ๆ ซึ่งฟีเจอร์นี้เราจะได้พบเจอมันบน Windows 8

Windows Store Apps App Bar : TopAppBar  / BottomAppBar

โดยใน Windows Store Apps เราไม่จำเป็นจะต้องหา Icons ต่าง ๆ เหล่านี้มาแสดงผลเหมือนบน Windows Phone เพราะใน Windows Store Apps ได้เตรียม Icon เหล่านี้มาให้หลายตัว เช่น Icon="Refresh" แสดงปุ่ม Refresh , Icon="Help" แสดงปุ่ม Help และปุ่มอื่น ๆ อีกมากมาย ที่สามารถเรียกใช้งานได้ทันที

เราสามารถสร้าง AppBar ได้โดยการสร้าง Page.TopAppBar สำหรับ AppBar ข้างบนหรือ Page.BottomAppBar สำหรับ AppBar ข้างล่าง เหมือนโค้ดข้างล่าง

<Page.TopAppBar>
    <AppBar>
        <!-- AppBar content -->
    </AppBar>
</Page.TopAppBar>

<Page.BottomAppBar>
    <CommandBar>
        <!-- CommandBar content -->
    </CommandBar>
</Page.BottomAppBar>

เช่น
<Page.BottomAppBar>
    <CommandBar>
        <AppBarButton Label="Refresh" Icon="Refresh" Click="AppBarButton_Click"/>
        <AppBarButton Label="Help" Icon="Help" Click="AppBarButton_Click"/>

        <CommandBar.SecondaryCommands>
            <AppBarButton Label="Edit" Icon="Edit" Click="AppBarButton_Click"/>
            <AppBarButton Label="Remove" Icon="Remove" Click="AppBarButton_Click"/>
            <AppBarButton Label="Add" Icon="Add" Click="AppBarButton_Click"/>
        </CommandBar.SecondaryCommands>
    </CommandBar>
</Page.BottomAppBar>

จาก Code เราจะต้องสร้าง Event ของ Click="AppBarButton_Click" เพื่อรองรับ Event ที่จะเกิดขึ้น

        private void AppBarButton_Click(object sender, RoutedEventArgs e)
        {

        }









Example 1 สร้าง AppBar แบบ TopAppBar และ BottomAppBar

MainPage.xaml
<Page
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:WindowsStoreApps"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    x:Class="WindowsStoreApps.MainPage"
    mc:Ignorable="d">

    <Page.TopAppBar>
        <AppBar>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <StackPanel Orientation="Horizontal">
                    <Button Content="Home" Width="140" Height="80" Click="AppBarButton_Click"/>
                    <Button Content="Page 1" Width="140" Height="80" Click="AppBarButton_Click"/>
                    <Button Content="Page 2" Width="140" Height="80" Click="AppBarButton_Click"/>
                </StackPanel>
                <SearchBox Grid.Column="1" Width="300" Height="50" HorizontalAlignment="Right"/>
            </Grid>
        </AppBar>
    </Page.TopAppBar>
    

    <Page.BottomAppBar>
        <CommandBar>
            <AppBarButton Label="Refresh" Icon="Refresh" Click="AppBarButton_Click"/>
            <AppBarButton Label="Help" Icon="Help" Click="AppBarButton_Click"/>

            <CommandBar.SecondaryCommands>
                <AppBarButton Label="Edit" Icon="Edit" Click="AppBarButton_Click"/>
                <AppBarButton Label="Remove" Icon="Remove" Click="AppBarButton_Click"/>
                <AppBarButton Label="Add" Icon="Add" Click="AppBarButton_Click"/>
            </CommandBar.SecondaryCommands>
        </CommandBar>
    </Page.BottomAppBar>

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Button x:Name="btnShow" Content="Show Bar" HorizontalAlignment="Left" Margin="549,351,0,0" VerticalAlignment="Top" FontSize="48" Click="btnShow_Click" FontFamily="Global User Interface"/>
    </Grid>

</Page>

MainPage.xaml.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.UI.Popups;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace WindowsStoreApps
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    /// 

    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
        }

        private void AppBarButton_Click(object sender, RoutedEventArgs e)
        {
            MessageDialog msgDialog = new MessageDialog("AppBar Clicked", "Hi");
            msgDialog.ShowAsync();

        }

        private void btnShow_Click(object sender, RoutedEventArgs e)
        {
            if (this.TopAppBar != null)
            {
                this.TopAppBar.IsOpen = true;
            }

            if (this.BottomAppBar != null)
            {
                this.BottomAppBar.IsOpen = true;
            }
        }

    }
}


Screenshot

Windows Store Apps App Bar : TopAppBar  / BottomAppBar

แสดงหน้าจอซึ่งเราจะให้คลิกที่ Button และแสดง App Bat

Windows Store Apps App Bar : TopAppBar  / BottomAppBar

แสดง App Bar ทั้ง TopAppBar และ BottomAppBar

Windows Store Apps App Bar : TopAppBar  / BottomAppBar

เมื่อทดสอบการคลิกที่ App Bar บน Icon ต่าง ๆ ก็จะเกิด Event ตามที่เรากำนดไว้

Example 2 สร้าง AppBar แบบ BottomAppBar ด้วย CommandBar รูปแบบอื่น ๆ
    <Page.BottomAppBar>
        <CommandBar>
            <AppBarToggleButton Icon="Shuffle" Label="Shuffle" Click="AppBarButton_Click"/>
            <AppBarToggleButton Icon="RepeatAll" Label="Repeat" Click="AppBarButton_Click"/>
            <AppBarSeparator/>
            <AppBarButton Icon="Back" Label="Back" Click="AppBarButton_Click"/>
            <AppBarButton Icon="Stop" Label="Stop" Click="AppBarButton_Click"/>
            <AppBarButton Icon="Play" Label="Play" Click="AppBarButton_Click"/>
            <AppBarButton Icon="Forward" Label="Forward" Click="AppBarButton_Click"/>

            <CommandBar.SecondaryCommands>
                <AppBarButton Icon="Like" Label="Like" Click="AppBarButton_Click"/>
                <AppBarButton Icon="Dislike" Label="Dislike" Click="AppBarButton_Click"/>
            </CommandBar.SecondaryCommands>
        </CommandBar>
    </Page.BottomAppBar>


Screenshot

Windows Store Apps App Bar : TopAppBar  / BottomAppBar

แสดง CommandBar ที่อยู่ภายใต้ CommandBar และ BottomAppBar







.

   
Share


ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2014-02-20 20:50:03 / 2017-03-19 14:46:15
  Download : No files
 Sponsored Links / Related

 
Windows Store Apps กับ Template เช่น Blank , Grid , Hub , Split Apps (C#)
Rating :

 
โครงสร้างของ Project บน Windows Store Apps และไฟล์ต่าง ๆ ที่เกี่ยวข้อง (C#)
Rating :

 
Page และ Controls หรือ Toolbox เครื่องมือสำหรับออกแบบ UI บน XAML (C#)
Rating :

 
รู้จัก Toolbox และ Controls พื้นฐานเช่น TextBlock , TextBox และ Button (C#)
Rating :

 
ListBox แสดงข้อมูลแบบ List และ Combobox บน Windows Store (C#)
Rating :

 
ListView และ GridView บน Windows Store Apps (C#)
Rating :

 
FlipView สร้าง Image FlipView / Image Slide บน Windows Store Apps (C#)
Rating :

 
เล่นไฟล์ Media / Sound เช่น Video Clip / Sound ด้วย MediaElement (C#)
Rating :

 
WebView แสดงผล URL เว็บไซต์ หรือ HTML บน Windows Store Apps (C#)
Rating :

 
เล่นไฟล์ยูทูป บน Windows Store Apps ด้วย MediaElement (C#)
Rating :

 
File Pickers กับ Save Dialog / Open Dialog บน Windows Store Apps (C#)
Rating :

 
Context Menus and Popup Menu บน Windows Store Apps (C#)
Rating :

 
Geolocation and Location หาตำแหน่งของ Client ที่ใช้งาน Apps ของเรา (C#)
Rating :

 
Windows Store App และ Progress Bar การสร้าง Progress Bar (C#)
Rating :


ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 03
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่