我想在我的窗口phone8 App中使用功能,即在用户点击手机屏幕时应生成一个圆圈。在android和IOS中有一个事件Touchpose。在wp8中是否有任何等效的touchpose方法。 或者在用户点按(点击)屏幕上创建圆圈的任何其他方式。提前谢谢。
答案 0 :(得分:0)
当然,你可以。如果您的布局基于网格,那么这是我的示例,您可以如何做到这一点。
XAML:
<Page /* all the default stuff */>
<Grid Tapped="Grid_Tapped" Background="Black">
// Your content
</Grid>
</Page>
C#:
private void Grid_Tapped(object sender, TappedRoutedEventArgs e)
{
Ellipse ellipse = new Ellipse()
{
Width = 64,
Height = 64,
Fill = new SolidColorBrush(Colors.Red),
Opacity = 0.2,
IsHitTestVisible = false, // This makes the circle transparent for touch, so you can tap things under it.
};
Grid.SetColumnSpan(ellipse, 99); // You need this if you have more columns than one.
Grid.SetRowSpan(ellipse, 99); // You need this if you have more rows than one.
Point position = e.GetPosition((Grid)sender);
ellipse.VerticalAlignment = VerticalAlignment.Top; // This will allow us to use top margin as Y coordinate.
ellipse.HorizontalAlignment = HorizontalAlignment.Left; // This will allow us to use left margin as X coordinate.
ellipse.Margin = new Thickness(position.X - ellipse.Width / 2, position.Y - ellipse.Height / 2, 0, 0); // Place the circle where user taps.
((Grid)sender).Children.Add(ellipse);
}
请注意,主网格的背景不能透明,否则不会触发Tapped
事件。
如果你愿意,你也可以为圆圈设置动画,改变它的大小和颜色,让它在一段时间后消失......