我的CS没有在我的XAML中看到x:Name资源。 '图像x:名称=" Imag1" '必须遗漏一些明显的东西。有人可以帮忙吗?
XAML:
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:XamarinFormsCamera" x:Class="EnSpect.XamarinFormsCameraPage">
<StackLayout Padding="20">
<Button Text="Select Image" HorizontalOptions="CenterAndExpand" Clicked="SelectImageClicked"></Button>
<Image x:Name="Imag1" Aspect="AspectFit" WidthRequest="300"></Image>
</StackLayout>
</ContentPage>
CS:
using System;
using System.IO;
using Xamarin.Forms;
namespace EnSpect
{
public partial class XamarinFormsCameraPage : ContentPage
{
public XamarinFormsCameraPage()
{
InitializeComponent();
MessagingCenter.Subscribe<byte[]>(this, "ImageSelected", (args) =>
{
Device.BeginInvokeOnMainThread(() =>
{
//Set the source of the image view with the byte array
Imag1.Source = ImageSource.FromStream(() => new MemoryStream((byte[])args));
});
});
}
答案 0 :(得分:0)
我最近遇到了这个问题,只是决定将解决方案留在这里。我单击了ExampleView.xaml> ExampleView.xaml.cs> ExampleView旁边的箭头,然后打开了InitializeComponent。如果要添加标签,在其中您会在私有void InitializeComponent中看到所有引用的元素
"dateOfBirth" : { $dateToString: { format: "%Y-%m-%d", date:
"$dateOfBirth" } }
您要添加的私有void InitializeComponent上方
ExampleLabel = global::Xamarin.Forms.NameScopeExtensions.FindByName<global::Xamarin.Forms.Label>(this, "ExampleLabel");
您应该注意到正在生成另一个文件,然后我能够引用我的元素。
希望有帮助!
编辑:仅当添加x:Name =“ PropertyName”不起作用时