国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

第11章 樣式(1)——概述、創建和使用

2019-11-14 10:38:16
字體:
來源:轉載
供稿:網友

樣式:封裝一系列屬性的集合,如外邊距、內邊距、顏色、字體等。

①一般在設置樣式時都要指明TargeType屬性,否則用Setter設置屬性時會非常麻煩,比如必須寫Button.FontSize或TextBlock.FontFamily等。

②若定義樣式的時候不使用x:Key鍵名,則TargeType屬性就會作為自動應用樣式的快捷鍵。

③樣式的鍵名有兩種寫法,它倆是等效的:x:Key="{x:Type Button}"和x:Key="Button"

④通過設置元素的Style="{x:Null}",可以刪除自動應用的樣式。

下面列舉三個個樣式的實例代碼:

屬性觸發器例子:

<Window x:Class="Styles.SimpleTriggers"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/PResentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    Title="SimpleTriggers" Height="300" Width="300"    >  <Window.Resources>    <Style x:Key="BigFontButton">      <Style.Setters>        <Setter Property="Control.FontFamily" Value="Times New Roman" />                <Setter Property="Control.FontSize" Value="18" />            </Style.Setters>      <Style.Triggers>        <Trigger Property="Control.IsFocused" Value="True">          <Setter Property="Control.Foreground" Value="DarkRed" />        </Trigger>        <Trigger Property="Control.IsMouSEOver" Value="True">          <Setter Property="Control.Foreground" Value="LightYellow" />          <Setter Property="Control.FontWeight" Value="Bold" />        </Trigger>                <Trigger Property="Button.IsPressed" Value="True">          <Setter Property="Control.Foreground" Value="Red" />        </Trigger>      </Style.Triggers>    </Style>  </Window.Resources>  <StackPanel Margin="5">    <Button Padding="5" Margin="5" Style="{StaticResource BigFontButton}" >A Customized Button</Button>    <TextBlock Margin="5">Normal Content.</TextBlock>    <Button Padding="5" Margin="5">A Normal Button</Button>    <TextBlock Margin="5">More normal Content.</TextBlock>    <Button Padding="5" Margin="5" Style="{StaticResource BigFontButton}">Another Customized Button</Button>  </StackPanel></Window>

事件觸發器例子:

<Window x:Class="Styles.EventTriggers"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    Title="EventTriggers" Height="300" Width="300"    >  <Window.Resources>    <Style x:Key="BigFontButton">      <Style.Setters>        <Setter Property="Control.FontFamily" Value="Times New Roman" />        <Setter Property="Control.FontSize" Value="18" />        <Setter Property="Control.FontWeight" Value="Bold" />      </Style.Setters>            <Style.Triggers>        <EventTrigger RoutedEvent="Mouse.MouseEnter">          <EventTrigger.Actions>            <BeginStoryboard>              <Storyboard>                <DoubleAnimation                  Duration="0:0:0.2"                  Storyboard.TargetProperty="FontSize"                  To="22"  />              </Storyboard>            </BeginStoryboard>          </EventTrigger.Actions>        </EventTrigger>        <EventTrigger RoutedEvent="Mouse.MouseLeave">          <EventTrigger.Actions>            <BeginStoryboard>              <Storyboard>                <DoubleAnimation                  Duration="0:0:1"                  Storyboard.TargetProperty="FontSize"  />              </Storyboard>            </BeginStoryboard>          </EventTrigger.Actions>        </EventTrigger>      </Style.Triggers>    </Style>      </Window.Resources>  <StackPanel Margin="5">    <Button Padding="5" Margin="5" Style="{StaticResource BigFontButton}">A Customized Button</Button>    <TextBlock Margin="5">Normal Content.</TextBlock>    <Button Padding="5" Margin="5">A Normal Button</Button>    <TextBlock Margin="5">More normal Content.</TextBlock>    <Button Padding="5" Margin="5" Style="{StaticResource BigFontButton}">Another Customized Button</Button>  </StackPanel></Window>自動應用樣式例子:

<Window x:Class="Styles.AutomaticStyles"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    Title="AutomaticStyles" Height="300" Width="300"    >  <Window.Resources>    <Style TargetType="Button">      <Setter Property="FontFamily" Value="Times New Roman" />      <Setter Property="FontSize" Value="18" />      <Setter Property="FontWeight" Value="Bold" />    </Style>  </Window.Resources>  <StackPanel Margin="5">    <Button Padding="5" Margin="5">Customized Button</Button>    <TextBlock Margin="5">Normal Content.</TextBlock>    <Button Padding="5" Margin="5" Style="{x:Null}"            >A Normal Button</Button>    <TextBlock Margin="5">More normal Content.</TextBlock>    <Button Padding="5" Margin="5">Another Customized Button</Button>  </StackPanel></Window>


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 兴和县| 筠连县| 洛宁县| 阿坝县| 连平县| 政和县| 四子王旗| 奇台县| 汝州市| 江都市| 商城县| 宾阳县| 余干县| 友谊县| 阜阳市| 陈巴尔虎旗| 宁乡县| 准格尔旗| 仪陇县| 来宾市| 霸州市| 开鲁县| 凤山县| 安远县| 富源县| 观塘区| 兴安盟| 丹东市| 霍城县| 蒙阴县| 新安县| 宿松县| 赤峰市| 肃北| 灵武市| 依安县| 万年县| 台山市| 华蓥市| 定陶县| 左云县|