WFP ?????????????????????
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WFP ?????????????????????相关的知识,希望对你有一定的参考价值。
??????????????? target smo ?????? animation tle text converter sele
WPF???????????????html???CSS????????????????????????????????????????????????????????????????????????????????????????????????????????????
???????????????????????????????????????????????? ????????????<Style> </Style>????????????
<Window.Resources> <FontFamily x:Key="ButtonFontFamily">Times New Roman</FontFamily> <sys:Double x:Key="ButtonFontSize">18</sys:Double> <FontWeight x:Key="ButtonFontWeight">Bold</FontWeight> </Window.Resources>
?????????????????????
????????????
<Window.Resources> <Style x:Key="BigFontButtonStyle" TargetType="TextBlock"> //????????????????????????TextBlock ????????????<Setter Property="Control.FontFamily" Value="Times New Roman"/> ????????????<Setter Property="Control.FontSize" Value="{DynamicResource ButtonFontSize}"/>//?????????????????????????????? ????????????<Setter Property="Control.FontWeight" Value="Bold"/> ??? </Style> </Window.Resources>
???????????????????????????????????????????????????????????????TextBlock????????? ???????????????<Style TargetType="TextBlock">????????????????????????x:Key="BigFontButtonStyle"
<Window.Resources> <Style TargetType="TextBlock"> <Setter Property="HorizontalAlignment" Value="Center"/> <Setter Property="TextAlignment" Value="Center"/> <Setter Property="Padding" Value="5"/> </Style> </Window.Resources>
?????????????????????
???????????????????????????????????????????????????????????????????????????????????????????????????
<Window.Resources> <Style x:Key="BaseOnStyle" TargetType="TextBlock"> <Setter Property="HorizontalAlignment" Value="Center"/> <Setter Property="TextAlignment" Value="Center"/> <Setter Property="Padding" Value="5"/> </Style> <Style x:Key="TextBlockStyle" TargetType="TextBlock" BasedOn="{StaticResource BaseOnStyle}"> <Setter Property="Control.Foreground" Value="Red"/> </Style> </Window.Resources>
?????????????????????
???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
<TextBlock x:Name="textBlock" TextWrapping="Wrap" Text="????????????" Style="{DynamicResource TextBlockStyle}" />
?????????????????????????????????????????????
<TextBlock x:Name="textBlock" TextWrapping="Wrap" Text="????????????" FontFamily="{DynamicResource ButtonFontFamily}" />
?????????????????????
WPF???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????XAML?????????????????????
<Window x:Class="StyleDemo.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="Red" /> </Trigger> <!--?????????????????????--> <Trigger Property="Control.IsMouseOver" Value="True"> <Setter Property="Control.Foreground" Value="Yellow" /> <Setter Property="Control.FontWeight" Value="Bold" /> </Trigger> <!--?????????????????????--> <Trigger Property="Button.IsPressed" Value="True"> <Setter Property="Control.Foreground" Value="Blue" /> </Trigger> </Style.Triggers> </Style> </Window.Resources> <StackPanel Margin="5"> <Button Padding="5" Margin="5" Style="{StaticResource BigFontButton}" >A Big Button</Button> <TextBlock Margin="5">Normal Content.</TextBlock> <Button Padding="5" Margin="5" >A Normal Button</Button> </StackPanel> </Window>
?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????MouseEnter?????????????????????MouseEnter?????????????????????????????????FontSize???????????????????????????????????????XAML?????????????????????
<Window x:Class="StyleDemo.EventTrigger" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="EventTrigger" 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> <!--???0.2?????????????????????????????????22??????--> <Storyboard> <DoubleAnimation Duration="0:0:0.2" Storyboard.TargetProperty="FontSize" To="22" /> </Storyboard> </BeginStoryboard> </EventTrigger.Actions> </EventTrigger> <!--???????????????????????????--> <EventTrigger RoutedEvent="Mouse.MouseLeave"> <EventTrigger.Actions> <BeginStoryboard> <!--???1??????????????????????????????????????????????????????--> <!--????????????????????????????????????????????????WPF?????????????????????????????????????????????????????????--> <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 Big Button</Button> <TextBlock Margin="5">Normal Content.</TextBlock> <Button Padding="5" Margin="5" >A Normal Button</Button> </StackPanel> </Window>
???????????????
?????????????????????TextBox???Text????????????7???????????????Border??????????????????XAML???????????????
<Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:WpfApplication1" Title="WPF???????????????" Height="500" Width="800" WindowStartupLocation="CenterScreen"> <Window.Resources> <local:L2BConverter x:Key="cvtr" /> <Style TargetType="TextBox"> <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={x:Static RelativeSource.Self},Path=Text.Length,Converter={StaticResource cvtr}}" Value="false"> <Setter Property="BorderBrush" Value="Red"/> <Setter Property="BorderThickness" Value="1"/> </DataTrigger> </Style.Triggers> </Style> </Window.Resources> <StackPanel> <TextBox Margin="5"/> <TextBox Margin="5,0"/> <TextBox Margin="5"/> </StackPanel> </Window>
???????????????Converter????????????????????????Converter???
using System; using System.Windows.Data; namespace WpfApplication1 { public class L2BConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { int textLength = (int)value; return textLength > 6 ? true : false; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } }
???????????????
EventTrigger??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????Setter???????????????????????????????????????UI???????????????????????????EventTrigger????????????
?????????????????????????????????????????????Button???Style?????????Style????????????EventTrigger????????????MouseEnter???????????????????????????MouseLeave???????????????XAML???????????????
<Window.Resources> <Style TargetType="Button"> <Style.Triggers> <!--????????????--> <EventTrigger RoutedEvent="MouseEnter"> <BeginStoryboard> <Storyboard> <DoubleAnimation To="150" Duration="0:0:0.2" Storyboard.TargetProperty="Width"/> <DoubleAnimation To="150" Duration="0:0:0.2" Storyboard.TargetProperty="Height"/> </Storyboard> </BeginStoryboard> </EventTrigger> <!--????????????--> <EventTrigger RoutedEvent="MouseLeave"> <BeginStoryboard> <Storyboard> <DoubleAnimation Duration="0:0:0.2" Storyboard.TargetProperty="Width"/> <DoubleAnimation Duration="0:0:0.2" Storyboard.TargetProperty="Height"/> </Storyboard> </BeginStoryboard> </EventTrigger> </Style.Triggers> </Style> </Window.Resources> <Canvas> <Button Width="40" Height="40" Content="OK"/> </Canvas>
以上是关于WFP ?????????????????????的主要内容,如果未能解决你的问题,请参考以下文章