
教學網站:
WPF Tutorial.net
比較使用XAML與標準程式碼的差異,
其實使用XAML就像是在寫HTML網頁,
簡單來說就是將設計與程式碼分開來 :)
XAML語法格式:
1 2 3 4 | < StackPanel > < TextBlock Margin = "20" >Welcome to the World of XAML</ TextBlock > < Button Margin = "10" HorizontalAlignment = "Right" >OK</ Button > </ StackPanel > |
C#原始碼格式:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | // Create the StackPanel StackPanel stackPanel = new StackPanel(); this .Content = stackPanel; // Create the TextBlock TextBlock textBlock = new TextBlock(); textBlock.Margin = new Thickness(10); textBlock.Text = "Welcome to the World of XAML" ; stackPanel.Children.Add(textBlock); // Create the Button Button button = new Button(); button.Margin= new Thickness(20); button.Content = "OK" ; stackPanel.Children.Add(button); |
由語法與程式碼就可明顯發現兩者的差異性,而其顯現的結果皆相同。
沒有留言:
張貼留言