在我的WP7
应用程序中,InvalidOperationException
被扔进了设备中(虽然它在模拟器中运行良好)。从提供的堆栈Microsoft
跟踪来看,似乎源代码可能是以下代码。
Image start_rec = (Image)FindName(start_name);
// Return the general transform for the specified visual object.
GeneralTransform generalTransform1 = canvas1.TransformToVisual(start_rec);
pt = generalTransform1.Transform(new Point(0, 0));
double start_y = pt.Y * (-1);
double start_x = pt.X * (-1);
Image destination_rec = (Image)FindName("dot" + destination_name);
// Return the general transform for the specified visual object.
generalTransform1 = canvas1.TransformToVisual(destination_rec);
// Retrieve the point value relative to the child.
pt = generalTransform1.Transform(new Point(0, 0));
double destination_y = pt.Y * (-1);
double destination_x = pt.X * (-1);
我在上面的代码中尝试做的事情:canvas1
. 我正在尝试在画布上获取图像的位置。
我的问题是为什么我得到Exception
?
编辑:堆栈跟踪是
Frame Image Function Offset
0 coredll.dll xxx_RaiseException 19
1 mscoree3_7.dll 436172
2 mscoree3_7.dll 383681
3 mscoree3_7.dll 540620
4 TransitionStub 0
5 Microsoft.Xna.Framework.Audio.SoundEffect.Play 200
6 Microsoft.Xna.Framework.Audio.SoundEffect.Play 68
7 BoxIt.MainPage.correct_line 1780
8 BoxIt.MainPage.evaluate 360
9 BoxIt.MainPage.canvas1_ManipulationCompleted 196
10 MS.Internal.CoreInvokeHandler.InvokeEventHandler 2752
11 MS.Internal.JoltHelper.FireEvent 1324
12 mscoree3_7.dll 428848
13 mscoree3_7.dll 430212
14 mscoree3_7.dll 610999
15 mscoree3_7.dll 374145
16 0
17 agcore.dll CCoreServices::CLR_FireEvent 385
18 npctrl.dll CControlBase::ScriptCallback 435
19 npctrl.dll CXcpDispatcher::OnScriptCallback 547"
编辑 2:函数内的代码correct_line()
void correct_line(int a_h, int a_v)
{
Point pt;
int destination_num;
string destination_name;
string[] words = start_name.Split('t');
//textBox1.Text = words[1];
int.TryParse(words[1], out destination_num);
int start_num = destination_num;
destination_num = destination_num + a_h + a_v * 4;
// textBox1.Text = start_num + " " + destination_num;
Boolean u = true;
if (list.Count > 0)
{
u=!(list.Contains(start_num + destination_num));
}
if (u)
{
if (start_num > 0 & destination_num > 0)
{
int po = Math.Abs(start_num-destination_num);
if(po==1 | po==4)
{
destination_name = (destination_num).ToString();
Image start_rec = (Image)FindName(start_name);
// Return the general transform for the specified visual object.
GeneralTransform generalTransform1 = canvas1.TransformToVisual(start_rec);
pt = generalTransform1.Transform(new Point(0, 0));
double start_y = pt.Y * (-1);
double start_x = pt.X * (-1);
Image destination_rec = (Image)FindName("dot" + destination_name);
// Return the general transform for the specified visual object.
generalTransform1 = canvas1.TransformToVisual(destination_rec);
// Retrieve the point value relative to the child.
pt = generalTransform1.Transform(new Point(0, 0));
double destination_y = pt.Y * (-1);
double destination_x = pt.X * (-1);
//textBox1.Text = " " + start_num + " " + a_h + " " + destination_num + " " + a_v ;
Line line = new Line() { X1 = start_x + dotwidth / 2, Y1 = start_y + dotwidth / 2, X2 = destination_x + dotwidth / 2, Y2 = destination_y + dotwidth / 2 };
if (msg == "2" & move == 2)
{
line.Stroke = new SolidColorBrush(Colors.Black);
}
else
{
line.Stroke = new SolidColorBrush(Colors.White);
}
line.StrokeThickness = 15;
line.SetValue(Canvas.ZIndexProperty, 25);
line.Tag = "correct_line";
this.canvas1.Children.Add(line);
if (gsplay == 1)
{
//stroke.Play();
strokemusic.Play();
}
//
update_matrix(start_num, destination_num);
list.Add(start_num + destination_num);
//
h = 0;
v = 0;
//move = checkfor_box(start_num, destination_num, a_h, a_v);
move = checkfor_box3();
find_move();
}
}
}
}
Soundeffect
在OnNavigatedTo
函数中启动
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (settings.Contains("gs"))
{
string hx = (string)settings["gs"];
if (hx == "1")
{
gsplay = 1;
var laserStream1 = Application.GetResourceStream(new Uri("boxdone.wav", UriKind.Relative));
boxdonemusic = SoundEffect.FromStream(laserStream1.Stream);
var laserStream2 = Application.GetResourceStream(new Uri("stroke.wav", UriKind.Relative));
strokemusic = SoundEffect.FromStream(laserStream2.Stream);
}
else
{
gsplay = 0;
}
}
}