旅游网站界面设计h5网站不利于优化吗
旅游网站界面设计,h5网站不利于优化吗,公司网站推广执行方案,成都到西安防疫政策WPF中自动增加行#xff08;动画#xff09;的TextBox 原文:WPF中自动增加行#xff08;动画#xff09;的TextBoxWPF中自动增加行#xff08;动画#xff09;的TextBox WPF中的Textbox控件是可以自动换行的#xff0c;只要设置TextWrapping属性为”Wrap”即可#xff… WPF中自动增加行动画的TextBox 原文:WPF中自动增加行动画的TextBox WPF中自动增加行动画的TextBox WPF中的Textbox控件是可以自动换行的只要设置TextWrapping属性为”Wrap”即可但是存在一个问题Textbox的高度是固定的当输入文本过多时就会出现如下情况。 Textbox虽然没有自动增加高度的属性但是我们可以通过设置来实现这一个功能。相关xaml代码如下 Grid VerticalAlignmentTop HorizontalAlignmentLeft Width36 Height100TextBox x:NametextBox TextWrappingWrap VerticalAlignmentTop //Grid效果如下 这里需要注意的是 如果设置了textBox的Width、Height或者Margin属性那么此textBox的大小就已经限制死了不会自动增加会出现上图中的情况。如果想设置textBox的大小和位置需要把textBox放在一个Grid中通过Grid的属性来控制textBox上文中xaml文件中的方法其实到此为止所需要的功能已经实现了但是为了让让textbox更美观我加了一个动画 效果如下 表面上看是一个textbox其实是一个Grid加上2个textBox一个显示一个隐藏xaml代码如下 GridTextBox x:NametxtVisible TextWrappingWrap/TextBox x:NametxtHidden TextWrappingWrap VisibilityHidden VerticalAlignmentTop/
/GridGrid是用来控制textbox的大小的两个textbox中显示的那个用于输入文字隐藏的用于触发动画。原理如下 在txtVisible中输入文字的同时txtVisible把text传递给txtHidden当txtHidden中的内容已经满一行时会触发SizeChange事件这个事件再触发txtVisible高度变化动画。代码如下 public partial class txt : UserControl
{private HeightAnimation anim;private double _animationDuration;public txt(){InitializeComponent();// Initialize the animationanim new HeightAnimation(this);AnimationDuration 500; //default value// Add the handlers to the required eventstxtHidden.SizeChanged TxtHidden_SizeChanged;txtVisible.TextChanged TxtVisible_TextChanged;}/// summary/// Gets or sets a value indicating whether the control is animated on loaded./// /summarypublic bool AnimateOnLoaded { get; set; } false;/// summary/// Gets or sets a value indicating whether the control is animated./// /summarypublic bool IsAnimated { get; set; } true;/// summary/// Gets or sets the duration of the animation./// /summarypublic double AnimationDuration{get { return _animationDuration; }set{_animationDuration value;anim.Duration new Duration(TimeSpan.FromMilliseconds(value));}}/// summary/// Gets or sets the text contents of the AnimatedTextBox./// /summarypublic string Text{get { return txtHidden.Text; }set{txtHidden.Text value;txtVisible.Text value;}}private void TxtVisible_TextChanged(object sender, TextChangedEventArgs e){// When the users writing in txtVisible, we copy the text to txtHiddentxtHidden.Text txtVisible.Text;}private void TxtHidden_SizeChanged(object sender, SizeChangedEventArgs e){OnHeightChanged(e.PreviousSize.Height, e.NewSize.Height);}/// summary/// To execute when the txtHiddens Height has changed./// /summaryprivate void OnHeightChanged(double previousHeight, double newHeight){//Animation type, increase txtVisibles height or decreaseanim.ChangeType (newHeight previousHeight) ? HeightAnimation.ChangeTypes.Increased : HeightAnimation.ChangeTypes.Decreased;// Animate the Height from the txtHiddens previousHeight to its newHeightanim.From previousHeight;anim.To newHeight;// Start the animationanim.BeginAnimation();}/// summary/// Manages the AnimatedTextBox Heights animation./// /summaryprivate class HeightAnimation{private Storyboard sb;private DoubleAnimation anim;private double _from;private double _to;private Duration _duration;private FrameworkElement _fe;private ChangeTypes _changeType;/// summary/// The possible types of the Height change./// /summarypublic enum ChangeTypes{Increased,Decreased}/// summary/// Constructor of the class./// /summarypublic HeightAnimation(FrameworkElement fe){// Set the FrameworkElement which manages the animation_fe fe;// Initialize the Storyboardsb new Storyboard();sb.AutoReverse false;// Initialize the animationanim new DoubleAnimation();anim.Name anim;// Set the EasingFunction on a new instance of CubicEase whose EasingMode is EaseInOutanim.EasingFunction new CubicEase() { EasingMode EasingMode.EaseInOut };// Bind the Animation with the txtVisible TextBoxStoryboard.SetTargetName(anim, txtVisible);// Add the animation to the Storyboards childrensb.Children.Add(anim);}/// summary/// Gets or sets the type of the Height change./// /summarypublic ChangeTypes ChangeType{get { return _changeType; }set{_changeType value;/* If the Height has inreased, set the target property to MaxHeight, else to MinHeight* (instead of animating directly the Height, we animate MaxHeight/MinHeight to prevent the AnimatedTextBox* from growing/shrinking suddenly) */Storyboard.SetTargetProperty(anim, new PropertyPath(string.Format((TextBox.{0}), (value ChangeTypes.Increased) ? MaxHeight : MinHeight)));}}/// summary/// Gets or sets the animations starting Height./// /summarypublic double From{get { return _from; }set{_from value;anim.From value;}}/// summary/// Gets or sets the animations ending Height./// /summarypublic double To{get { return _to; }set{_to value;anim.To value;}}/// summary/// Gets or sets the animations duration./// /summarypublic Duration Duration{get { return _duration; }set{_duration value;anim.Duration value;}}/// summary/// Begins the animation./// /summarypublic void BeginAnimation(){_fe.BeginStoryboard(sb);}}
}posted on 2019-01-15 17:08 NET未来之路 阅读(...) 评论(...) 编辑 收藏 转载于:https://www.cnblogs.com/lonelyxmas/p/10272989.html
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/88088.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!