Frage

I´ve downloaded the MSDN sample project for learning things about usage of the phone camera. I´m developing a Windows Phone 8 app.

When starting the downloaded project, everything is fine.

Now I want to include some basics in my own project. After copying the XAML and XAML.CS into my project, I got the following error:

'GestureEventArgs' is an ambiguous reference between 'System.Windows.Input.GestureEventArgs' and 'Microsoft.Phone.Controls.GestureEventArgs'

This references to following code by 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().";
                });
            }
        }
    }

I don´t understand, what´s going wrong here... Any help?

War es hilfreich?

Lösung

It seems that you have both of following using statements :

using System.Windows.Input;
using Microsoft.Phone.Controls;

which can cause conflict since there is a different GestureEventArgs class defined in each of above namespace.

You can use namespace alias to resolve this conflict, for example, add following using statement if you meant to use GestureEventArgs from System.Windows.Input.GestureEventArgs namespace :

using GestureEventArgs = System.Windows.Input.GestureEventArgs;

void focus_Tapped(object sender, GestureEventArgs e)
{
    .......
}

or another option is using fully-qualified class name :

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

Andere Tipps

You probably have installed the Window Phone Toolkit on your project.

In Windows Phone 7, the Toolkit added an API to manage gestures. On Windows Phone 8, this functionality is built-in, so that's why you have two classes with the same name and the compiler doesn't know which one to use.

What you should do is indicate the compiler what class to use, just by prefixing it with the namespace of the built-in API (System.Windows.Input):

void focus_Tapped(object sender, System.Windows.Input.GestureEventArgs e)
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top