c# - CS 0102: 类型“ ”已包含“ ”的定义
问题描述
我的标题错误 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;
});
};
}
}
}
解决方案
除非 EditMemberPage.cs 的内容比您向我们展示的更多,否则请查看 EditMemberPage.xaml。您可能有两个带有 x:Name="takePhoto" 的元素。
具有 x:Name 的元素在该类中创建一个成员,其名称是 x:Name 的值。因此,您不能有多个具有相同 x:Name 的元素,也不能在 C# 中声明一个与元素的 x:Name 具有相同名称的成员。
推荐阅读
- matplotlib - 在决策边界图中显示评估指标
- python - Matplotlib:为什么我的列表理解没有堆积条形图?
- python - 条件格式化具有不同颜色的python数据框列值
- html - 使用钩子形成 onChange 事件不会更新变量
- spring-boot - spring-boot azure spring data cosmos 喜欢返回空
- url - 带有 url-loader 的 Vite
- less - 如何在 Magento2 的 xml 文件中包含更少的文件?
- python - 根据某个参数检查多个变量的更简单方法?
- nginx - 使用 NGINX 流式传输 mp4 视频中的问题
- kubernetes - 无法在 Jaeger UI 中看到完整的跨度