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

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

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

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

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

①一般在設置樣式時都要指明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>


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 洞头县| 江城| 武功县| 疏勒县| 美姑县| 宾川县| 柳河县| 阳新县| 专栏| 永宁县| 武安市| 诸城市| 荣昌县| 揭西县| 惠东县| 苍南县| 叶城县| 东台市| 霍州市| 施秉县| 会昌县| 治多县| 古田县| 蓬安县| 德令哈市| 贵阳市| 北辰区| 五常市| 大丰市| 衡东县| 临邑县| 全南县| 罗甸县| 辰溪县| 庆安县| 兴化市| 武城县| 开远市| 德庆县| 通江县| 沾益县|