C# 在Windows Phone 8上实现MSDN基本摄像头示例时出错
我下载了MSDN示例项目,以了解手机摄像头的使用情况。我正在开发一个WindowsPhone8应用程序 启动下载的项目时,一切正常 现在我想在我自己的项目中包括一些基础知识。在将XAML和XAML.CS复制到我的项目中后,我出现以下错误: “GestureEventArgs”是“System.Windows.Input.GestureEventArgs”和“Microsoft.Phone.Controls.GestureEventArgs”之间的不明确引用 MSDN引用了以下代码:C# 在Windows Phone 8上实现MSDN基本摄像头示例时出错,c#,windows-phone-8,C#,Windows Phone 8,我下载了MSDN示例项目,以了解手机摄像头的使用情况。我正在开发一个WindowsPhone8应用程序 启动下载的项目时,一切正常 现在我想在我自己的项目中包括一些基础知识。在将XAML和XAML.CS复制到我的项目中后,我出现以下错误: “GestureEventArgs”是“System.Windows.Input.GestureEventArgs”和“Microsoft.Phone.Controls.GestureEventArgs”之间的不明确引用 MSDN引用了以下代码: //
// Provide touch focus in the viewfinder.
void focus_Tapped(object sender, GestureEventArgs e)
{
if (cam != null)
{
if (cam.IsFocusAtPointSupported == true)
{
try
{
// Determine location of tap.
Point tapLocation = e.GetPosition(viewfinderCanvas);
// Position focus brackets with estimated offsets.
focusBrackets.SetValue(Canvas.LeftProperty, tapLocation.X - 30);
focusBrackets.SetValue(Canvas.TopProperty, tapLocation.Y - 28);
// Determine focus point.
double focusXPercentage = tapLocation.X / viewfinderCanvas.Width;
double focusYPercentage = tapLocation.Y / viewfinderCanvas.Height;
// Show focus brackets and focus at point
focusBrackets.Visibility = Visibility.Visible;
cam.FocusAtPoint(focusXPercentage, focusYPercentage);
// Write a message to the UI.
this.Dispatcher.BeginInvoke(delegate()
{
txtDebug.Text = String.Format("Camera focusing at point: {0:N2} , {1:N2}", focusXPercentage, focusYPercentage);
});
}
catch (Exception focusError)
{
// Cannot focus when a capture is in progress.
this.Dispatcher.BeginInvoke(delegate()
{
// Write a message to the UI.
txtDebug.Text = focusError.Message;
// Hide focus brackets.
focusBrackets.Visibility = Visibility.Collapsed;
});
}
}
else
{
// Write a message to the UI.
this.Dispatcher.BeginInvoke(delegate()
{
txtDebug.Text = "Camera does not support FocusAtPoint().";
});
}
}
}
我不明白,这里出了什么问题。。。有什么帮助吗?您似乎有以下两种用法:
using System.Windows.Input;
using Microsoft.Phone.Controls;
这可能会导致冲突,因为在上述每个命名空间中定义了不同的GestureEventArgs
类
您可以使用来解决此冲突,例如,如果要从System.Windows.Input.GestureEventArgs
命名空间使用GestureEventArgs
,请添加以下using语句:
using GestureEventArgs = System.Windows.Input.GestureEventArgs;
void focus_Tapped(object sender, GestureEventArgs e)
{
.......
}
或者另一个选项是使用完全限定的类名:
void focus_Tapped(object sender, System.Windows.Input.GestureEventArgs e)
{
.......
}
您可能已经在项目中安装了Windows Phone工具包 在WindowsPhone7中,工具包添加了一个API来管理手势。在Windows Phone 8上,此功能是内置的,因此您有两个同名的类,而编译器不知道要使用哪个类 您应该做的是通过在编译器前面加上内置API的名称空间(
System.Windows.Input
)来指示要使用的类:
或者,您也可以直接在using语句中执行此操作:
using GestureEventArgs=System.Windows.Input.GestureEventArgs代码>
void focus_Tapped(object sender, System.Windows.Input.GestureEventArgs e)