WPF中Lable不自动换行
如果在WPF Label里面的字符串太长,想让它自动换行,可以用TextBlock实现
<Label MaxWidth="550">
<TextBlock TextWrapping="Wrap"
Text="在此输入要换行的文字,前提是它足够长,并且Label的MaxWidth不足以让它一行显示。" />
</Label>
如果想在长字符串的某个位置强制换行,可以用
<Label MaxWidth="550">
<TextBlock TextWrapping="Wrap"
Text="在此输入要换行的文字,前提是它足够长 并且Label的MaxWidth不足以让它一行显示。" />
</Label>
这样它就换行了!
遍历的时候不允许数组发生变化
不要在枚举集合的操作(例如foreach)中去执行修改集合的操作。很多文章中提出解决方法是将foreach改为for循环,这里记录一种简便方法。如果需要修改集合,那么你应该先使用 ToArray() 方法,例如
foreach (var x in Mylist.ToArray())
{
这里执行可能修改Mylist的操作
}
[WPF] 动画Completed事件里获取执行该动画的UI对象
WPF里动画的Completed的本身并不会返回执行动画的UI对象,但我们可以利用附加属性Storyboard.TargetProperty来达到我们想要的效果。
步骤:
1 在执行动画前,先附加属性记录对象
DoubleAnimation ani = new DoubleAnimation();
ani.From = start;
ani.To = end;
ani.Duration = new Duration(TimeSpan.FromSeconds(0.25));
ani.Completed += ani_Completed;
/* !!! 附加属性Storyboard.Target,用于指定执行动画的UI对象 !!! */
Storyboard.SetTarget(ani, uiElement);
/* 启动动画 */
uiElement.BeginAnimation(Canvas.LeftProperty, ani);
2 在动画的Completed事件方法里取回
if (sender is AnimationClock)
{
AnimationTimeline timeline = (sender as AnimationClock).Timeline;
/* !!! 通过附加属性把UI对象取回 !!! */
object uiElement = Storyboard.GetTarget(timeline);
}
DevExpress GridControl 显示行号、设置行号宽
设置行号宽
gridView1.IndicatorWidth = 30;
显示行号
private void gridView1_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
{
if (e.Info.IsRowIndicator && e.RowHandle > -1)
{
e.Info.DisplayText = (e.RowHandle + 1).ToString();
}
}
DEV控件GridControl显示水平滚动条
设置GridControl的属性ColumnAutoWidth = False。
设置过程:Run Designer —>Property Editor—>Views—>Options—>OptionsView—>ColumnAutoWidth