【发布时间】:2018-11-16 11:46:37
【问题描述】:
我有一个 ImageCell 作为 ListView 的一部分,它应该显示通过数据绑定从页面的 ViewModel 获得的三条信息。
XAML:
<ListView x:Name="ScoreListView" ItemsSource="{Binding DBScores}"
IsPullToRefreshEnabled="True" RefreshCommand="{Binding RefreshScoresAsyncCommand}" IsRefreshing="{Binding IsBusy, Mode=OneWay}">
<ListView.ItemTemplate>
<DataTemplate>
<ImageCell
Text="{Binding DisplayName}"
Detail="{Binding Points}"
ImageSource="{Binding SyncImagePath}"/>
</DataTemplate>
</ListView.ItemTemplate>
C#
DBScores = new ObservableCollection<ScoresTable>();
...
var downloadedList = await App.AzureService.GetScores();
downloadedList = downloadedList.OrderByDescending(x => x.Points).ThenBy(x => x.DisplayName).ToList();
DBScores = new ObservableCollection<ScoresTable>();
foreach (ScoresTable element in downloadedList)
{
if(element.Synced == 0)
{
element.SyncImagePath = "notsynced.png";
}
else
{
element.SyncImagePath = "synced.png";
}
DBScores.Add(element);
}
...
public class ScoresTable
{
[JsonProperty("Id")]
public string Id { get; set; }
public string DisplayName { get; set;}
public int Points { get; set; }
public DateTime AchievedOn { get; set; }
public int Synced { get; set; }
public string Latitude { get; set; }
public string Longitude { get; set; }
[JsonIgnore]
public string SyncImagePath { get; set; }
}
DisplayName 和 Points 的绑定工作得很好。我将相关图像放置在我的 Android 项目的 Resources/drawable 文件夹中,并将它们添加到 Visual Studio 项目中。他们的名字拼写正确并且大小写正确。当我从数据库加载图像时,我检查它们的Synced 属性并将图像路径设置为两个图像之一; synced.png 或 notsynced.png
我很茫然,因为这在我昨天回家时有效,但现在无效。我尝试在 VS 中清理并手动删除 bin 和 obj 文件夹并重建项目。
编辑 1; Build Actions 设置为 AndroidResource
编辑 2; This 是我看到的
【问题讨论】:
-
你的android项目中图像的构建动作是什么?它应该设置为“AndroidResource”。
-
就是,两张图片都设置成这个i.imgur.com/2ZGPvYO.png
-
您是否尝试过清理解决方案?并确保手动删除“bin”和“obj”文件夹...有时资源不会再次打包。
-
我有,不过我会再试一次。更新;没有运气。
-
我已将版本降级回 3.3.0.967583,它突然又可以工作了。发行说明中没有提到对这些内容的任何更改。我应该早点想到这一点,缓慢的一天......
标签: xamarin.forms