我想加載一些圖片的串列。
我不知道為什么用 c# 代碼加載圖片這么難,我嘗試了很多路徑(見截圖);我所有的照片都有構建動作“嵌入式資源”
代碼
使用 xaml 加載圖片沒有問題,通過 imageCell 加載圖片也沒有問題我可以將文本“Hello”添加到我的堆疊面板(stackkkk)中,但不是影像:(
這是 xaml: Xaml
var image = new Image { Source ="tattrank.images.indexPic.jpg"};
var image2 = new Image { Source = "images.indexPic.jpg" };
var image3 = new Image { Source = "/images.indexPic.jpg" };
var image4 = new Image { Source = "indexPic.jpg" };
Label lbl = new Label();
lbl.Text = "Hello";
stackkk.Children.Add(img);
stackkk.Children.Add(lbl);
stackkk.Children.Add(image);
stackkk.Children.Add(image2);
stackkk.Children.Add(image3);
stackkk.Children.Add(image4);
stackkk.Children.Add(lbl);
這是 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"
x:Class="tattrank.MainPage"
xmlns:localPic="clr-namespace:tattrank">
<ScrollView>
<StackLayout x:Name="stackkk">
<Image Source="{localPic:image tattrank.images.indexPic.jpg}" HeightRequest="250"/>
<Label Text="DIndexPage" FontSize="Title" Padding="30,10,30,10"/>
<Label FontSize="16" Padding="30,24,30,0"/>
<TableView Intent="Settings">
<TableRoot x:Name="tbRoot">
<TableSection Title="XamlCode" x:Name="TbSection">
<SwitchCell Text="New Voice Mail" />
<SwitchCell Text="New Mail" On="true" />
</TableSection>
</TableRoot>
</TableView>
</StackLayout>
</ScrollView>
</ContentPage>
uj5u.com熱心網友回復:
根據檔案,從嵌入式資源加載影像
Image embeddedImage = new Image
{
Source = ImageSource.FromResource("WorkingWithImages.beach.jpg", typeof(MyClass).GetTypeInfo().Assembly)
};
MyClass
與影像位于同一程式集中的類的名稱在哪里
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/493332.html