XAML
XAML (Ex tensible A pplication M arkup L anguage i )是Windows Presentation Foundation (WPF)和Universal Windows Platform (UWP)的一部分,是微软 开发的一種基于XML 、基于声明,用于初始化结构化值和对象的使用者介面 宣告式程式設計 ,它有著HTML 的外觀,又揉合了XML語法的本質,例如:可以使用<Button> 標籤設定按鈕(Button)。它類似Linux 平台下的glade。至於WinFX XAML Browser Application (XBAP)是用XAML作界面描述,在瀏覽器中執行的程式,可取代過去的ActiveX 、Java Applet 、Flash 。
XAML本質上屬於一種.NET 编程语言,屬於通用語言運行庫 (Common Language Runtime),同C# 、VB.NET 等同。與HTML類似,特点是用來描述使用者介面。XAML的语法格式为:<Application... />,Application是必備的基本元素。XAML可以定義2D和3D物件、旋轉(rotations)、動畫(animations),以及各式各樣的效果。
Hello world
<Page
x:Class= "UwpAppExample.MainPage"
xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x= "http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local= "using:UwpAppExample"
xmlns:d= "http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc= "http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable= "d"
Background= "{ThemeResource ApplicationPageBackgroundThemeBrush}" >
<Grid>
<Button Margin= "10,0,10,0" Height= "100" Click= "Hello_Click" Content= "Click Me!" />
</Grid>
</Page>
using System ;
using Windows.UI.Xaml.Controls ;
namespace UwpAppExample
{
public sealed partial class MainPage : Page
{
public MainPage ()
{
this . InitializeComponent ();
}
private async void Button_Click ( object sender , Windows . UI . Xaml . RoutedEventArgs e )
{
await new Windows . UI . Popups . MessageDialog ( "Hello World!" ). ShowAsync ();
}
}
}
<Window x:Class= "WpfAppExample.MainWindow"
xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x= "http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d= "http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc= "http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local= "clr-namespace:WpfAppExample"
mc:Ignorable= "d"
Title= "MainWindow" Height= "350" Width= "525" >
<Grid>
<Button Margin= "10,0,10,0" Height= "100" Click= "Hello_Click" Content= "Click Me!" />
</Grid>
</Window>
using System.Windows ;
namespace WpfAppExample
{
public partial class MainWindow : Window
{
public MainWindow ()
{
InitializeComponent ();
}
private void Hello_Click ( object sender , RoutedEventArgs e )
{
MessageBox . Show ( "Hello World!" );
}
}
}
<Window x:Class= "WpfAppExample.MainWindow"
xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x= "http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d= "http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc= "http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local= "clr-namespace:WpfAppExample"
mc:Ignorable= "d"
Title= "MainWindow" Height= "350" Width= "525" >
<Grid>
<Button Margin= "10,0,10,0" Height= "100" Click= "Hello_Click" Content= "Click Me!" />
</Grid>
</Window>
Imports System.Windows
Class MainWindow
Sub New ()
InitializeComponent ()
End Sub
Private Sub Hello_Click ( sender As Object , e As RoutedEventArgs )
MessageBox . Show ( "Hello World!" )
End Sub
End Class
参考资料
外部連結
实现 架構 共同語言基礎架構 CLI支持語言
Core家族3 元件 比較 即將推出
The article is a derivative under the Creative Commons Attribution-ShareAlike License .
A link to the original article can be found here and attribution parties here
By using this site, you agree to the Terms of Use . Gpedia ® is a registered trademark of the Cyberajah Pty Ltd