CS 0102:类型' '已包含'的定义'

时间:2018-04-25 00:50:35

标签: c# xamarin xamarin.forms

我有标题错误CS 0302说明"类型' EditMemberPage'已经包含了' takePhoto的定义,我的代码与第30行相关联。我正在尝试使用媒体插件用iPhone模拟器拍照。这是代码:

using Relate.Model;
using Plugin.Media;
using Plugin.Media.Abstractions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;


namespace Relate.Views
{
    public partial class EditMemberPage : ContentPage
    {

        public EditMemberPage()
        {
            InitializeComponent();

            takePhoto.Clicked += async (sender, args) =>
            {

                if (!CrossMedia.Current.IsCameraAvailable || 
        !CrossMedia.Current.IsTakePhotoSupported)
                {
                    DisplayAlert("No Camera", ":( No camera avaialble.", "OK");
                    return;
                }

                var file = await CrossMedia.Current.TakePhotoAsync(new 
        Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    Directory = "Test",
                    SaveToAlbum = true,
                    CompressionQuality = 75,
                    CustomPhotoSize = 50,
                    PhotoSize = PhotoSize.MaxWidthHeight,
                    MaxWidthHeight = 2000,
                    DefaultCamera = CameraDevice.Front
                    });

                if (file == null)
                    return;

                DisplayAlert("File Location", file.Path, "OK");

                image.Source = ImageSource.FromStream(() =>
                  {
                  var stream = file.GetStream();
                  file.Dispose();
                  return stream;
              });
            };
        }
    }

}

1 个答案:

答案 0 :(得分:0)

除非您向EditMemberPage.cs提供更多信息,否则请查看EditMemberPage.xaml。你可能有两个带x的元素:Name =" takePhoto"。

具有x:Name的元素在该类中创建一个成员,其名称是x:Name的值。因此,您不能拥有多个具有相同x:Name的元素,也不能在C#中声明一个与元素名称相同的成员&x;名称。