国产探花免费观看_亚洲丰满少妇自慰呻吟_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>


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 锡林浩特市| 迁安市| 平阴县| 铜陵市| 咸丰县| 水城县| 永春县| 永平县| 伊川县| 乌审旗| 任丘市| 成都市| 龙州县| 河源市| 浮梁县| 静海县| 德安县| 鞍山市| 岑巩县| 定远县| 岳池县| 山东省| 肥城市| 定安县| 拉孜县| 阳城县| 赣榆县| 茶陵县| 永州市| 汝州市| 海城市| 香格里拉县| 子长县| 鹿邑县| 凤阳县| 商南县| 门源| 安平县| 漯河市| 昂仁县| 宁陵县|