xaml - 如何在 Xamarin.Forms UWP 中使用图像?

标签 xaml xamarin xamarin.forms uwp uwp-xaml

我目前正在 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

enter image description here

最佳答案

对于 UWP 中的 Xamarin Forms,图像必须位于根项目目录(而不是 Assets )中,并且构建操作设置为 Content。

图像将在 Xamarin Forms 中像在 Android 和 iOS 中一样工作。

关于xaml - 如何在 Xamarin.Forms UWP 中使用图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38026687/

相关文章:

xamarin - 无法更改导航栏背景颜色 Xamarin 表单

c# - Xamarin - Prism : How do I pass the whole ViewModel of the ContentPage to a child ContentView

wpf - 如何在控件模板中为 WPF 中的 ListView 列应用 MinWidth?

wpf - WPF 绑定(bind)中单引号的用途是什么?

wcf - 为 netstandard Xamarin.Forms 项目生成 WCF 客户端代理

.net - 为 Xamarin Studio(Gtk#) 安装 gstreamer-sharp

ios - Xamarin 无法识别已安装的字体

xaml - 如何更改 Xamarin.Forms xaml 页面中的图标颜色?

wpf - 从默认样式继承样式

c# - 如何摆脱XAML WP8.1中的命名空间错误