【问题标题】:Creating a marquee lookalike in Windows Store Apps在 Windows 应用商店应用程序中创建类似的选取框
【发布时间】:2015-07-14 01:25:14
【问题描述】:
我正在尝试创建 this(html) 的等价物
<marquee behavior="alternate">Your bouncing text goes here</marquee>
在 Windows 应用商店应用程序中,使用 C#
是否有任何控件可以做到这一点,还是我必须创建一个自定义控件?
【问题讨论】:
标签:
c#
windows-runtime
windows-store-apps
marquee
【解决方案1】:
Windows 应用商店应用中没有选取框控件。
我已经设法找到代码做一些类似于你正在尝试做的事情。去看看WPF Marquee Text Animation。如果您使用该代码,您应该能够获得想要的结果
与 Marquee 的主要区别在于,一旦您到达屏幕边缘,您就想从另一个方向返回。像获取 textblock 和 grid 中的 Width 并减去它们一样简单的事情可以给你想要的结果
一种方法是这样的:
-
获取控件的宽度差异
int TotalMargin = gridTest.Width - textblocktest.Width
-
然后您需要不断地为您的边距添加一个值
if textblocktest.Margin.Left < TotalMargin {
textBlock.Margin = New Thickness(textblock.Margin.Left + aNumber,0,0,0)
}
else{
//Call a procedure doing the same thing but decrementing the margin until it is at 0 and then going back to adding margin
}