У меня есть Xaml Page ListView, который правильно отображает данные в UWP, но не корректно отображает данные в iOS.Я использую HttpClient для получения данных от локального веб-интерфейса, подключенного к SQL Server, работающему на локальном компьютере.Я думаю, что это как-то связано с настройкой NSUrlSession, работающей с HttpClient.Какие-либо предложения?Это Xaml Page.
<?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:telerikDataControls="clr-namespace:Telerik.XamarinForms.DataControls;assembly=Telerik.XamarinForms.DataControls"
xmlns:viewModels="clr-namespace:SxQiApp.ViewModels;assembly=SxQiApp"
xmlns:telerikListView="clr-namespace:Telerik.XamarinForms.DataControls.ListView;assembly=Telerik.XamarinForms.DataControls"
x:Class="SxQiApp.DailyCasePage">
<ContentPage.BindingContext>
<viewModels:VSxCaseViewModel />
</ContentPage.BindingContext>
<ContentPage.Content>
<telerikDataControls:RadListView x:Name="listView"
ItemsSource="{Binding SxCases}"
ItemTapped="listView_ItemTappedAsync"
SelectedItem="{Binding SelectedSxCase, Mode=TwoWay}">
<telerikDataControls:RadListView.ItemTemplate>
<DataTemplate>
<telerikListView:ListViewTemplateCell>
<telerikListView:ListViewTemplateCell.View>
<StackLayout>
<Label Text="Surgery Cases" />
<Label Text="{Binding Facesheet}" />
<Label Text="{Binding Record}" />
</StackLayout>
</telerikListView:ListViewTemplateCell.View>
</telerikListView:ListViewTemplateCell>
</DataTemplate>
</telerikDataControls:RadListView.ItemTemplate>
</telerikDataControls:RadListView>
</ContentPage.Content>
</ContentPage>
Это код позади.
using System.Threading.Tasks;
using SxQiApp.Models;
using SxQiApp.ViewModels;
using Xamarin.Forms;
namespace SxQiApp
{
// XamlC is set in App.xaml.cs
//[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class DailyCasePage : ContentPage
{
public DailyCasePage()
{
InitializeComponent();
}
private async void listView_ItemTappedAsync(object sender, Telerik.XamarinForms.DataControls.ListView.ItemTapEventArgs e)
{
var sxcase = e.Item as SxCase;
if (sxcase != null)
{
var SxCaseViewModel = new SxCaseViewModel();
if (SxCaseViewModel != null)
{
SxCaseViewModel.SelectedSxCase = sxcase;
await Navigation.PushAsync(new EditSxCasePage(SxCaseViewModel));
}
}
}
}
}
Это ViewModel.
using SxQiApp.Models;
using SxQiApp.Services;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using Xamarin.Forms;
namespace SxQiApp.ViewModels
{
public class VSxCaseViewModel : INotifyPropertyChanged
{
private List<SxCase> _sxcase;
private VSxCaseDataService _vsxCaseDataService = new VSxCaseDataService();
private SxCase _selectedSxCase;
public SxCase SelectedSxCase
{
get { return _selectedSxCase; }
set
{
_selectedSxCase = value;
OnPropertyChanged();
}
}
public List<SxCase> SxCases
{
get
{
return _sxcase;
}
set
{
_sxcase = value;
OnPropertyChanged();
}
}
public ICommand AddRecordCommand => new Command(async () =>
{
await _vsxCaseDataService.PostSxCase(SelectedSxCase);
});
//public ICommand EditSxCaseCommand => new Command(async () =>
//{
// await _vsxCaseDataService.PutSxCase(SelectedSxCase);
//});
public Command EditSxCaseCommand
{
get
{
return new Command(async () =>
{
var sxCaseDataService = new SxCaseDataService();
await sxCaseDataService.PutSxCase(_selectedSxCase.Id, _selectedSxCase);
});
}
}
public VSxCaseViewModel()
{
SelectedSxCase = new SxCase();
GetSxCases();
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName]string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private async Task GetSxCases()
{
SxCases = await _vsxCaseDataService.GetSxCases();
}
}
}
Это сервисный код
using Newtonsoft.Json;
using SxQiApp.Models;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
namespace SxQiApp.Services
{
class VSxCaseDataService
{
private string Url = "http://localhost:19952/api/vsxcases/";
public async Task<List<SxCase>> GetSxCases()
{
var httpClient = new HttpClient();
var json = await httpClient.GetStringAsync(Url);
var sxcases = JsonConvert.DeserializeObject<List<SxCase>>(json);
return sxcases;
}
public async Task PostSxCase(SxCase sxcase)
{
var httpClient = new HttpClient();
var json = JsonConvert.SerializeObject(sxcase);
StringContent content = new StringContent(json);
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var result = await httpClient.PostAsync(Url, content);
}
public async Task PutSxCase(int sxcaseid, SxCase selectedSxCase)
{
var httpClient = new HttpClient();
var json = JsonConvert.SerializeObject(selectedSxCase);
StringContent content = new StringContent(json);
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var result = await httpClient.PutAsync(Url + sxcaseid, content);
}
}
}