• 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>
    三思而又行。
  • 相关阅读:
    浅谈Android中Activity的生命周期
    探索ASP.NET MVC框架之控制器的查找与激活机制
    探索ASP.NET MVC框架之路由系统
    浅谈JavaScript中的defer,async
    浅谈MVC中路由
    JavaScript中一些怪异用法的理解
    split
    您正在搜索的页面可能已经删除、更名或暂时不可用。
    C#中的Attributes的用法
    Timeout expired 超时时间已到. 达到了最大池大小 错误及Max Pool Size设置
  • 原文地址:https://www.cnblogs.com/jun-jie/p/3728071.html
Copyright © 2020-2023  润新知