我目前正在 Xamarin.Forms UWP 中创建示例系统。我想知道为什么我调用图像的代码在 Android 中工作时在 UWP 部分似乎无法正常工作。我还想将图像设置为背景和图像作为按钮。
如何编写代码才能使其在两个平台上正常运行?
这是我使用的代码:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="XamarinFormsDemo.Views.LoginPage"
BackgroundImage="bg3.jpg"
Title="MainPage">
<Label Text="{Binding MainText}" VerticalOptions="Center" HorizontalOptions="Center" />
<StackLayout VerticalOptions="Center"
Padding="40">
<Image Source="ebmslogo1.png"/>
<StackLayout Padding="0,50,0,0">
<Entry x:Name="txtUserName"
Placeholder="Username"
x:Hint="Username"
BackgroundColor="Black"
TextColor="White"/>
<Entry x:Name="txtPassword"
Placeholder="Password"
IsPassword="true"
BackgroundColor="Black"
TextColor="White"/>
<Button Text="LOG IN"
FontSize="14"
BackgroundColor="Teal"
Clicked="NavigateButton_OnClicked"/>
</StackLayout>
</StackLayout>
</ContentPage>
我的图片位于.Droid > Resources > drawable
最佳答案
对于 UWP 中的 Xamarin Forms,图像必须位于根项目目录(而不是 Assets )中,并且构建操作设置为 Content。
图像将在 Xamarin Forms 中像在 Android 和 iOS 中一样工作。
关于xaml - 如何在 Xamarin.Forms UWP 中使用图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38026687/