Visual Studio Project Image Brand new zu Xamarin und ich habe mehr als ein verlorener Tag versuchen, ein einfaches Bild zu bekommen auf einer einfachen Seite anzuzeigen.Xamarin Forms Bild/Embedded Bildprobleme
ich Visual Studio 2017.
Das Bild verwenden als eingebettete Ressource festgelegt ist (siehe beiliegende Abbildung). Es gibt keine Fehler beim Ausführen, das Bild wird einfach nicht angezeigt.
Ich habe versucht, die folgenden:
<Image Source="XF0003.Assets.logo.png" />
<Image Source="Assets.logo.png" />
<Image Source="logo.png" />
<Image Source="{local:ImageResource XF0003.Assets.logo.png}" />
<Image Source="{local:ImageResource Assets.logo.png}" />
<Image Source="{local:ImageResource logo.png}" />
XAML Seite Code:
<?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:XF0003"
x:Class="XF0003.MainPage">
<StackLayout>
<Image Source="Assets.logo.png" />
<Label Text="Username" />
<Entry x:Name="usernameEntry" Placeholder="username" />
<Label Text="Password" />
<Entry x:Name="passwordEntry" IsPassword="true" />
<Button Text="Login" Clicked="PageOne" />
<Label x:Name="messageLabel" />
</StackLayout>
</ContentPage>
XAML.CS Seite Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace XF0003
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private async void PageOne(object sender, EventArgs e)
{
Navigation.InsertPageBefore(new Page1(), this);
await Navigation.PopAsync();
}
}
[ContentProperty("Source")]
public class ImageResourceExtension : Xamarin.Forms.Xaml.IMarkupExtension
{
public string Source { get; set; }
public object ProvideValue(IServiceProvider serviceProvider)
{
if (Source == null)
{
return null;
}
// Do your translation lookup here, using whatever method you require
var imageSource = ImageSource.FromResource(Source);
return imageSource;
}
}
}
Sie haben vergessen, das Bild hinzuzufügen –
Nicht sicher, was passiert ist, aber ich habe das Bild wieder zu meinem Beitrag hinzugefügt ... – jf974