a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁 > 學院 > 開發(fā)設計 > 正文

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

2019-11-14 10:10:20
字體:
供稿:網(wǎng)友

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

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

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

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

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

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

屬性觸發(fā)器例子:

<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>

事件觸發(fā)器例子:

<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>


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 玖玖精品在线 | 日韩精品久久久免费观看夜色 | 六月色婷婷 | 国产不卡免费 | 精品成人佐山爱一区二区 | 一本色道久久综合狠狠躁篇怎么玩 | 99国内精品久久久久久久 | 精品视频 免费 | 草逼操 | 视频一区 中文字幕 | 久久久久久久 | 久久久线视频 | 欧美黑人一级爽快片淫片高清 | 999精品一区| 国产一区二区三区在线 | 欧美日韩毛片 | 成人在线免费网站 | 免费a网站 | 精品视频99 | 中文字幕一区在线观看 | 久久99久久久久 | 国产黄色大片免费看 | 精品国产一区二区三区久久影院 | 国产剧情一区二区 | v片网站 | 亚洲精品在线播放 | 日日夜夜精品网站 | 激情久久av一区av二区av三区 | 欧美三级在线看 | 综合伊人 | 国产一区二区三区四区在线观看 | 国产欧美日韩综合 | 欧美精品一区二区三区在线 | 日本成人精品 | 国产日韩欧美激情 | 少妇被粗大的猛烈进大胸视频 | 免费超碰在线观看 | 亚洲午夜精品一区二区三区他趣 | 国产一区二区三区在线 | 久精品视频 | 色婷婷久久 |