【发布时间】:2017-01-11 08:36:44
【问题描述】:
首先,我是 Xamarin.Form 的新手。我正在努力从 Google 中获得最好的结果,但有些功能我什至无法得到很多搜索。
我正在创建一个 Xamarin.Form 应用程序。在那个应用程序中,我将图像存储为sql server 中的base64 string 格式,我在sql server 中的数据类型是varchar(Max)。
我的问题是,如何将base64 string 转换为图像并将图像绑定到列表视图。
Listview的代码:
<ListView x:Name="listView" HasUnevenRows="true" SeparatorColor="Gray">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Image Source="{Binding image}" Grid.Row="0"
Grid.RowSpan="3" Grid.Column="0"
HorizontalOptions="Center" HeightRequest="50"
VerticalOptions="Center">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="OnImageTapped" />
</Image.GestureRecognizers>
</Image>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
c#代码:
Public async Task loadDeveloperList()
{
try
{
List<employee> employeeDetail = new List<employee>();
HttpClient client = new HttpClient();
StringBuilder sb = new StringBuilder();
client.MaxResponseContentBufferSize = 256000;
var RestUrl = "http://example.com/Getemployee/";
var uri = new Uri(RestUrl);
actIndicator.IsVisible = true;
actIndicator.IsRunning = true;
var response = await client.GetAsync(uri);
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
List<employee> onjEmployee = JsonConvert.DeserializeObject<List<employee>>(content);
foreach (var item in onjEmployee)
{
employee emptemp = new employee()
{
empID = item.empID,
name = item.name,
city = item.city,
post = item.post,
salary = item.salary,
gender = item.gender,
image = item.image
};
string cFotoBase64 = emptemp.image;
byte[] ImageFotoBase64 = System.Convert.FromBase64String(cFotoBase64);
employeeDetail.Add(emptemp);
}
listView.ItemsSource = employeeDetail;
}
}
catch (Exception ex)
{
}
}
所以请任何人给我一个想法和任何解决方案。
【问题讨论】:
-
把你的员工类放到你的帖子里
标签: c# windows xaml xamarin.forms