Reputation: 4815
My Xamarin Forms app is acting strangely when running on Android. When I run on UWP everything appears to work fine, but when I launch the same app on Android, the public properties of the model I'm binding seem to disappear, as if they don't exist.
The model is defined as an interface as shown here:
public interface IRegionModel
{
string Id { get; set; }
string Name { get; set; }
string ShortName { get; set; }
string UrlName { get; set; }
string Description { get; set; }
string CityId { get; set; }
}
the implementation is pretty much identical:
public class RegionModel : IRegionModel
{
public string Id { get; set; }
public string Name { get; set; }
public string ShortName { get; set; }
public string UrlName { get; set; }
public string Description { get; set; }
public string CityId { get; set; }
}
and I'm populating my ViewModel with an observable collection of the RegionModel type:
public class RegionListViewModel : ViewModelBase
{
public ObservableCollection<IRegionModel> Regions { get; set; } = new ObservableCollection<IRegionModel>();
protected string CityId { get; set; }
public void Init(string cityId)
{
CityId = cityId;
}
public async override void Start()
{
base.Start();
LoadDesignData();
IsLoading = false;
}
protected override void LoadDesignData()
{
base.LoadDesignData();
for (var i = 1; i < 5; i++)
{
var model = new RegionModel()
{
Id = i.ToString(),
Description = "Region description " + i.ToString(),
ShortName = "Downtown",
Name = "Downtown",
UrlName = "Downtown",
CityId = "mcallen"
};
Regions.Add(model);
}
}
}
as you can see, I have access to each of the properties of the model, and populate them with my properties.
however when I run the app on android, these properties are immediately invisible:
I don't get any exceptions or errors, but the properties are simply not there.
I thought perhaps it was due to stale binaries (as suggested here: C# some public properties are not accessible, actually completely missing)
However, I did a full clean and manual clean, clearing out all the bin/obj folders manually on every single project and rebuilt it. In addition I made some code changes and XAML changes and those are showing up, so the project definitely appears to be updating...
what else could possibly be wrong here? How can properties just disappear?
Upvotes: 0
Views: 354
Reputation: 15161
If you have linked your assemblies the analyzer may have failed to determine those properties are really used and it has stripped them.
Set the linkage options to "SDK Only" and it should work.
Upvotes: 1