zoukankan      html  css  js  c++  java
  • WPF-样式

    <Window x:Class="Wpf.Window2"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:sys="clr-namespace:System;assembly=mscorlib"
            Title="Window2" Height="300" Width="300">
        <Window.Resources>
            <FontFamily x:Key="a1">Times New Roman</FontFamily>
            <sys:Double x:Key="a2">18</sys:Double>
            <FontWeight x:Key="a3">Bold</FontWeight>
            
            <Style x:Key="Big">
    <Style.Triggers>
                    <Trigger Property="Control.IsFocused" Value="true">
                        <Setter  Property="Control.Background" >
                            <Setter.Value>
                                <LinearGradientBrush>
                                    <GradientStop Color="Chocolate" Offset="0.3"></GradientStop>
                                    <GradientStop Color="White"></GradientStop>
                                </LinearGradientBrush>
                            </Setter.Value>
                        </Setter>
                    </Trigger>
                </Style.Triggers>
    
    
                <Setter Property="Control.FontSize" Value="35"></Setter>
                <Setter Property="Control.Background" >
                    <Setter.Value>
                        <LinearGradientBrush  StartPoint="0,0" EndPoint="1,1" >
                            <GradientStop Color="Beige" Offset="0.5"></GradientStop>
                            <GradientStop Color="HotPink"></GradientStop>
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
            </Style>
        </Window.Resources>
        <Grid>
            <StackPanel>
                <TextBox FontFamily="{StaticResource ResourceKey=a1}" FontWeight="{StaticResource ResourceKey=a3}" FontSize="{StaticResource ResourceKey=a2}"></TextBox>
                <TextBox  Style="{StaticResource ResourceKey=Big}"></TextBox>
                <TextBox x:Name="txt1"></TextBox>
            </StackPanel>
        </Grid>
    </Window>

    也可在后台代码输入—

    txt1.Style = (Style)this.FindResource("Big");

    以上为简单的样式行为,样式可分为:关联事件样式-多层样式-通过类型自动应用样式-触发器样式

    简单动画:实现文本框的文字放大缩小

    <Window x:Class="Wpf.Window3"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="Window3" Height="300" Width="300">
        <Window.Resources>
            <Style  x:Key="big" TargetType="TextBox">
                <Style.Triggers>
                    <EventTrigger RoutedEvent="TextBox.MouseEnter">
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation Duration="0:0:0.3" Storyboard.TargetProperty="FontSize" To="50"></DoubleAnimation>
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>
                    <EventTrigger RoutedEvent="TextBox.MouseLeave">
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation Duration="0:0:0.1" Storyboard.TargetProperty="FontSize" ></DoubleAnimation>
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>
                </Style.Triggers>
            </Style>
        </Window.Resources>
    
            <StackPanel>
            <TextBox   Style="{StaticResource big}" Height="100">3333312222222222222222222222222222222222222222222222222222221</TextBox>
        </StackPanel>
    
    </Window>
    三思而又行。
  • 相关阅读:
    VIPServer VS LVS
    阿里中间件
    每天进步一点点——Linux
    在线制图工具!!!
    test
    RHCE 基础学习
    TCP/IP源码(59)——TCP中的三个接收队列
    多队列网卡简介以及Linux通过网卡发送数据包源码解读
    Queueing in the Linux Network Stack !!!!!!!!!!!!!!!
    css选择器
  • 原文地址:https://www.cnblogs.com/jun-jie/p/3728071.html
Copyright © 2011-2022 走看看