【问题标题】:How do I implement a camera in my Xamarin.Forms app?如何在我的 Xamarin.Forms 应用程序中实现相机?
【发布时间】:2020-05-01 06:06:03
【问题描述】:

我按照以下教程进行操作 https://xamarinhelp.com/use-camera-take-photo-xamarin-forms/ (我安装的是3.1.3版本)

但我收到此错误: CS0103 当前上下文中不存在名称“PhotoImage”

在这个方法中:

private async void CameraButton_Clicked(object sender, EventArgs e) 
{
    var photo = await Plugin.Media.CrossMedia.Current.TakePhotoAsync(new plugin.Media.Abstractions.StoreCameraMediaOptions() { });

    if (photo != null)
        PhotoImage.Source = ImageSource.FromStream(() => { return photo.GetStream(); });
} 

我是 Xamarin 的新手,不知道如何解决这个问题。

【问题讨论】:

  • 如果发生这种情况,您没有完全按照教程进行操作。您是否将名为 PhotoImage 的控件放到表单上?代码格式一样吗?

标签: xamarin xamarin.forms


【解决方案1】:

从共享样本中,您可以检查Xaml 是否包含PhotoImage

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>

    <Image x:Name="PhotoImage" />
    <Button x:Name="CameraButton" Text="Take Photo" Grid.Row="1" />
</Grid>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-03
    • 2019-02-23
    • 2017-08-27
    • 2017-12-30
    • 1970-01-01
    • 2021-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多