C# 在Windows Phone c xaml上创建刮刮卡效果
我想在Windows Phone上创建一个刮擦卡效果。然而,我当前的解决方案看起来很慢,划痕效果看起来很奇怪,请参阅下面的屏幕截图。与我在iOS上看到的相比,体验非常差 如果有人能指引我,我将不胜感激。下面是我目前的代码C# 在Windows Phone c xaml上创建刮刮卡效果,c#,xaml,windows-phone-8,scratchcard,C#,Xaml,Windows Phone 8,Scratchcard,我想在Windows Phone上创建一个刮擦卡效果。然而,我当前的解决方案看起来很慢,划痕效果看起来很奇怪,请参阅下面的屏幕截图。与我在iOS上看到的相比,体验非常差 如果有人能指引我,我将不胜感激。下面是我目前的代码 <Grid Width="Auto" Height="Auto" Background="Black"> <Viewbox Margin="0" HorizontalAlignment="Center" VerticalAlig
<Grid Width="Auto" Height="Auto" Background="Black">
<Viewbox Margin="0" HorizontalAlignment="Center" VerticalAlignment="Center">
<Grid Height="60" Width="60" Background="White">
<InkPresenter x:Name="inkP" Width="60" Height="60">
<InkPresenter.Background>
<ImageBrush Stretch="Fill" ImageSource="/Assets/image.png"/>
</InkPresenter.Background>
<Grid Height="60" Width="60">
<TextBlock x:Name="lblsecretText" HorizontalAlignment="Center" TextWrapping="Wrap" Text="LOL" VerticalAlignment="Center" Width="60" Foreground="Black" TextAlignment="Center" FontSize="5.333"/>
</Grid>
</InkPresenter>
</Grid>
</Viewbox>
</Grid>
Stroke s;
int mycol = 0;
public MainPage()
{
InitializeComponent();
inkP.MouseMove += new MouseEventHandler(inkP_MouseMove);
for (int i = 0; i < 60; i++)
{
for (int l = 0; l < 60; l++)
{
Stroke bigStroke = new Stroke();
bigStroke.StylusPoints.Add(new StylusPoint(i, l));
inkP.Strokes.Add(bigStroke);
}
}
}
StylusPoint _lastPoint;
void inkP_MouseMove(object sender, MouseEventArgs e)
{
StylusPointCollection pointErasePoints = e.StylusDevice.GetStylusPoints(inkP);
pointErasePoints.Insert(0, new StylusPoint(e.GetPosition(inkP).X, e.GetPosition(inkP).Y));
//Compare collected stylus points with the ink presenter strokes and store the intersecting strokes.
StrokeCollection hitStrokes = inkP.Strokes.HitTest(pointErasePoints);
if (hitStrokes.Count > 0)
{
foreach (Stroke hitStroke in hitStrokes)
{
inkP.Strokes.Remove(hitStroke);
}
}
_lastPoint = pointErasePoints[pointErasePoints.Count - 1];
}
你的笔触一点一点地消失了 您可以通过将主页面构造函数更改为:
public MainPage()
{
InitializeComponent();
inkP.MouseMove += new MouseEventHandler(inkP_MouseMove);
for (int i = 0; i < 60; i++)
{
Stroke bigStroke = new Stroke();
for (int l = 0; l < 60; l++)
{
bigStroke.StylusPoints.Add(new StylusPoint(i, l));
}
inkP.Strokes.Add(bigStroke);
}
}
这将逐行添加笔划。
当你删除它们时,它们将被逐行删除。你是否调试/分析过你的代码以确定你的代码在哪里花费了大部分时间?我做了,但是效果不对。我正在尝试做类似的事情。你找到解决办法了吗?这个问题有解决办法吗?