- XAML 教程
- XAML - 主頁
- XAML - 概述
- XAML - 環境設定
- 在 MAC OS 上編寫 XAML 應用程式
- XAML 與 C# 程式碼
- XAML 與 VB.NET
- XAML - 構建模組
- XAML - 控制元件
- XAML - 佈局
- XAML - 事件處理
- XAML - 資料繫結
- XAML - 標記擴充套件
- XAML - 依賴項屬性
- XAML - 資源
- XAML - 模板
- XAML - 樣式
- XAML - 觸發器
- XAML - 除錯
- XAML - 自定義控制元件
- XAML 實用資源
- XAML - 快速指南
- XAML - 實用資源
- XAML - 討論
XAML - 視窗級
在視窗級別定義樣式,此視窗上的所有元素都可以訪問該樣式。下面是一個視窗級別的示例,其中所有三個文字塊和文字框都有一個公共樣式。
<Window x:Class = "Styles.MainWindow"
xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x = "http://schemas.microsoft.com/winfx/2006/xaml"
Title = "MainWindow" Height = "350" Width = "604">
<Window.Resources>
<Style TargetType = "TextBlock">
<Setter Property = "FontSize" Value = "24" />
<Setter Property = "Margin" Value = "5" />
<Setter Property = "FontWeight" Value = "Bold" />
</Style>
<Style TargetType = "TextBox">
<Setter Property = "HorizontalAlignment" Value = "Left" />
<Setter Property = "FontSize" Value = "24" />
<Setter Property = "Margin" Value = "5" />
<Setter Property = "Width" Value = "200" />
<Setter Property = "Height" Value = "40" />
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height = "Auto" />
<RowDefinition Height = "Auto" />
<RowDefinition Height = "Auto" />
<RowDefinition Height = "*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width = "*" />
<ColumnDefinition Width = "2*" />
</Grid.ColumnDefinitions>
<TextBlock Text = "First Name: "/>
<TextBox Name = "FirstName" Grid.Column = "1" />
<TextBlock Text = "Last Name: " Grid.Row = "1" />
<TextBox Name = "LastName" Grid.Column = "1" Grid.Row = "1" />
<TextBlock Text = "Email: " Grid.Row = "2" />
<TextBox Name = "Email" Grid.Column = "1" Grid.Row = "2"/>
</Grid>
</Window>
編譯並執行上述程式碼後,將生成以下輸出 −
xaml_styles.htm
廣告