0
我是新來的Xamarin平臺,我有一個本地託管數據庫在SQL Server 2014中使用PHP(藉助XAMP服務器)和表名稱ItemProductsDB
並保存圖像爲varbinary(MAX)
。我將數據庫中的所有其他詳細信息作爲字符串(例如產品名稱,產品ID等)進行了分類,但圖像如下所示爲byte[]
。需要檢索圖像(Varbinary MAX)從SQL Server 2014到Xamarin通過使用C#
public class Contactone
{
public int ID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string Price { get; set; }
public string Date { get; set; }
public byte[] Image { get; set; }
}
public class ContectList
{
public List<Contactone> contacts { get; set; }
}
我已經創建了CS頁面和XAML檢索除了圖像等數據,下面JsonParsingPage.cs代碼(這下面的代碼運行得很好,但沒有圖像的檢索)
public partial class JsonParsingPage : ContentPage
{
public JsonParsingPage()
{
InitializeComponent();
this.BackgroundImage = "background.png";
this.Title = "Meals";
GetJSON();
}
public async void GetJSON()
{
// Check network status
if (NetworkCheck.IsInternet())
{
var client = new System.Net.Http.HttpClient();
var response = await client.GetAsync("http://192.168.43.226/GetProducts.php");
string contactsJson = response.Content.ReadAsStringAsync().Result;
ContectList ObjContactList = new ContectList();
if (contactsJson != "")
{
//Converting JSON Array Objects into generic list
ObjContactList = JsonConvert.DeserializeObject<ContectList>(contactsJson);
}
//Binding listview with server response
listviewConacts.ItemsSource = ObjContactList.contacts;
}
else
{
await DisplayAlert("JSONParsing", "No network is available.", "Ok");
}
//Hide loader after server response
ProgressLoader.IsVisible = false;
}
該幕牆XAML代碼,如下面結合各自領域
e<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TestProject.Views.DetailViews.JsonParsingPage">
<Grid>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ListView x:Name="listviewConacts" Grid.Row="1" HorizontalOptions="FillAndExpand" HasUnevenRows="True" ItemSelected="listviewContacts_ItemSelected">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid HorizontalOptions="FillAndExpand" Padding="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Text="{Binding Name}" HorizontalOptions="StartAndExpand" Grid.Row="0" TextColor="White" FontAttributes="Bold"/>
<Label Text="{Binding Description}" HorizontalOptions="StartAndExpand" Grid.Row="1" TextColor="Orange" FontAttributes="Bold"/>
<Label Text="{Binding Price}" HorizontalOptions="StartAndExpand" Grid.Row="2" TextColor="Gray" FontAttributes="Bold"/>
<Label Text="{Binding Date}" HorizontalOptions="StartAndExpand" Grid.Row="3" TextColor="Gray" FontAttributes="Bold"/>
<Label Text="{Binding Image}" HorizontalOptions="StartAndExpand" Grid.Row="4" TextColor="Gray" FontAttributes="Bold"/>
<BoxView HeightRequest="2" Margin="0,10,10,0" BackgroundColor="Gray" Grid.Row="4" HorizontalOptions="FillAndExpand" />
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
<ActivityIndicator x:Name="ProgressLoader" IsRunning="True"/>
</Grid>
</ContentPage>
我的問題是:我有什麼做的,從SQL Server檢索和顯示varbinary
圖片他們在Xamarin形式(包括CS和XAML代碼)?
任何幫助,將不勝感激。
潘