【发布时间】:2020-06-10 04:41:18
【问题描述】:
我已经在屏幕上显示了除图像之外的数据现在我还想查看图像,因为我可以看到所有数据,例如 id 名称等,以下是代码: 我需要在哪里进行哪些更改?
第 1 页 XAML C 清晰代码:(此页面上的更改?)
public partial class MainPage : ContentPage
{
private static readonly HttpClient client = new HttpClient();
public UserResponse result;
public String test;
public MyUser user;
public MainPage()
{
InitializeComponent();
// Task.Run(async () => await GetinfoAsync());
_ = GetinfoAsync();
}
public async Task GetinfoAsync()
{
var responseString = await client.GetStringAsync("https://reqres.in/api/users/2");
result = JsonConvert.DeserializeObject<UserResponse>(responseString);
if (result != null)
{
Device.BeginInvokeOnMainThread(() =>
{
test = dis.Text = "Id:- " + result.Data.id + "\nEmail:- " + result.Data.email + "\nFirst Name:- " + result.Data.first_name + "\nLast Name:- " + result.Data.last_name + "\nImage:- " + result.Data.avatar; dis.Text = test;
});
}
}
private async void click_me(Object sender, EventArgs args)
{
await this.Navigation.PushAsync(new Data(result));
}
第 2 页 XAML C 语言代码:(此页面上的更改?)
public partial class Data : ContentPage
{
private MyUser _obj;
public MyUser obj
{
get { return _obj; }
set
{
_obj = value;
OnPropertyChanged();
}
}
public String show;
public Data(UserResponse result)
{
//show = test;
InitializeComponent();
obj = result.Data;
// displaylabel.Text = test;
}
用于设计的第 2 页 XAML 代码:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="demo.Data" x:Name="MyPage" >
<ContentPage.Content >
<StackLayout Padding="20">
<Label Text="Id" TextColor="Red" />
<Editor BindingContext="{x:Reference Name=MyPage}" Text="{Binding obj.id}" IsReadOnly="True" />
<Label Text="First Name" TextColor="Red"/>
<Editor BindingContext="{x:Reference Name=MyPage}" Text="{Binding obj.first_name}" IsReadOnly="True"/>
<Label Text="Last Name" TextColor="Red"/>
<Editor BindingContext="{x:Reference Name=MyPage}" Text="{Binding obj.last_name}" IsReadOnly="True"/>
<Label Text="Email" TextColor="Red"/>
<Editor BindingContext="{x:Reference Name=MyPage}" Text="{Binding obj.email}" IsReadOnly="True"/>
<Editor BindingContext="{x:Reference Name=MyPage}" Text="Image" IsReadOnly="True"/>
<Image BindingContext="{x:Reference Name=MyPage}" Source="{Binding obj.avatar}"/>
</StackLayout>
</ContentPage.Content>
</ContentPage>
【问题讨论】:
-
这个question发生了什么事
-
这能回答你的问题吗? Issue with showing the Image
-
我不太明白。所以我上传了另一个更详细的问题。所以请帮助我
-
@JamesS 不,先生,它不是因为我是 C 语言的新手并且第一次使用 xamarin
-
@SajawalZubairi 我不会为基本相同的问题上传新问题,而是使用附加信息编辑您先前存在的问题。
标签: c# json image xamarin xamarin.forms