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

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

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

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

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

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

②若定義樣式的時(shí)候不使用x:Key鍵名,則TargeType屬性就會(huì)作為自動(dòng)應(yīng)用樣式的快捷鍵。

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

④通過設(shè)置元素的Style="{x:Null}",可以刪除自動(dòng)應(yīng)用的樣式。

下面列舉三個(gè)個(gè)樣式的實(shí)例代碼:

屬性觸發(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>自動(dòng)應(yīng)用樣式例子:

<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ā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 肇州县| 如东县| 海口市| 呼和浩特市| 手游| 南陵县| 顺平县| 佛冈县| 得荣县| 阿图什市| 锡林浩特市| 扎兰屯市| 拉萨市| 礼泉县| 平度市| 合肥市| 扶风县| 沭阳县| 会宁县| 麻栗坡县| 上饶市| 平谷区| 枣阳市| 深圳市| 墨玉县| 凤山市| 墨玉县| 湘西| 涿鹿县| 威宁| 分宜县| 镇巴县| 东城区| 东丰县| 九龙坡区| 日照市| 宁夏| 鄂伦春自治旗| 青阳县| 萍乡市| 曲松县|