在windows Phone 8上实现MSDN基本相机样本时出现错误

本文关键字:样本 相机 错误 Phone windows MSDN 实现 | 更新日期: 2023-09-27 18:03:23

我已经下载了MSDN样例项目来学习手机摄像头的使用方法。我正在开发一个Windows Phone 8应用。

当启动下载的项目时,一切正常。

现在我想在我自己的项目中包含一些基础知识。在将XAML和XAML. cs复制到我的项目中之后,我得到了以下错误:

' gestreeventargs '是在'System.Windows.Input. args '之间的一个模糊引用。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().";
                });
            }
        }
    }

我不明白,这里出了什么问题…任何帮助吗?

在windows Phone 8上实现MSDN基本相机样本时出现错误

您似乎有以下两个using语句:

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 Toolkit。

在Windows Phone 7中,工具包增加了一个API来管理手势。在Windows Phone 8上,这个功能是内置的,所以这就是为什么你有两个同名的类,编译器不知道该使用哪个。

您应该做的是通过使用内置API (System.Windows.Input)的名称空间作为前缀来指示编译器要使用的类:

void focus_Tapped(object sender, System.Windows.Input.GestureEventArgs e)