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 > Mobile > Windows Phone Dev - สอนเขียน App บนโปรแกรม Windows Phone 7 , Windows Phone 8 > Margin Property และการจัดวาง Layout ในหน้า Silverlight Page, Windows Phone



Clound SSD Virtual Server

Margin Property และการจัดวาง Layout ในหน้า Silverlight Page, Windows Phone

Margin Property และการจัดวาง Layout ในหน้า Silverlight Page, Windows Phone ในการจัดวาง Layout บน Grid ของ Windows Phone (Silverlight) นั้น ในการวางตำแหน่งต่าง ๆ จะใช้ Margin ในการระบุตำแหน่งพิกัดที่อยู่ในหน้าจอของ Windows Phone โดยรูปแบบการใช้งานง่าย ๆ ดูภาพประกอบ

Margin Property Silverlight Page, Windows Phone


โดย Margin อ้างอิงจากภายใต้ Parent ของ Control นั้น ๆ

Margin Attribute
<frameworkElement Margin="left+right,top+bottom"/>

จาก Attribute ของ Margin จะเห็นว่าค่าตัวเลขจะเป็น Margin="ซ้าย,ขวา,บน,ล่าง"

ทดสอบการสร้าง Project บน Windows Phone

Margin Property Silverlight Page, Windows Phone

ออกแบบ XAML ดังภาพ

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Background="Coral" Grid.Row="1" Margin="12,0,12,426" ShowGridLines="True">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition  />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition  />
            </Grid.RowDefinitions>
            <TextBlock Grid.Column="0" Grid.Row="0" Text="First Name" HorizontalAlignment="Center" VerticalAlignment="Center" />
            <TextBlock Grid.Column="0" Grid.Row="1" Text="Last Name" HorizontalAlignment="Center" VerticalAlignment="Center" />
            <TextBox Grid.Column="1" Grid.Row="0" Margin="15,10,15,10" />
            <TextBox Grid.Column="1" Grid.Row="1" Margin="15,10,15,10" />
        </Grid>

    </Grid>

Code บน XML

Margin Property Silverlight Page, Windows Phone

จาก Code และภาพประกอบ จะเป็นตัวอย่างการจัดส่ง Grid และ Layout รวมทั้งการกำหนด Margin


Screenshot

Margin Property Silverlight Page, Windows Phone

แสดงผลบน Emulator

Margin Property Silverlight Page, Windows Phone

จากตัวอย่างถ้ามองในมุมมองของ Grid จะเห็นว่าจะถูกแบ่งเป็น Rows และ Column ดังภาพ








เพิ่มเติม
ในกรณีที่ต้องการกำหนด Margin ในส่วนของ Code ที่เป็น VB.NET และ C# สามารถใช้เป็น New Thickness(44, 63, 0, 0) เช่น

VB.NET
Dim button As New Button
button.Name = "btn1"
button.Content = "Submit"
button.Height = "72"
button.Width = "160"
button.Margin = New Thickness(44, 63, 0, 0)
AddHandler button.Click, AddressOf Me.buttonClick
ContentPanel.Children.Add(button)


C#
Button button = new Button();
button.Name = "btn1";
button.Content = "Submit";
button.Height = "72";
button.Width = "160";
button.Margin = new Thickness(44, 63, 0, 0);
button.Click += new System.EventHandler(this.buttonClick);
ContentPanel.Children.Add(button);


   
Share


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


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


   


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

 
Windows Phone and Grid จัดวาง Layout ด้วย RowDefinition และ ColumnDefinition
Rating :

 
Orientations Landscape มุมมอง Layout ในแนวตั้งและแนวนอนบน Windows Phone
Rating :

 
การสร้าง Page และการ Link แสดงและซ่อน Uri Page Navigation บน Windows Phone
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 อัตราราคา คลิกที่นี่