當我在調試模式下建設時,一切正常。在Release中構建時,我的MvxListView不會被填充。MVVMCross發佈版本無法正常工作(LinkerPleaseInclude Listview)
這與鏈接器和MvvmCross做反射魔術有關,因此鏈接器無法知道將綁定鏈接到哪裏。
他們說有一個名爲「LinkerPleaseInclude.cs」的文件來幫助僞造綁定作爲其引用。
不知怎的,我的列表視圖仍然沒有得到填充..請幫我...
Linkerpleaseinclude文件:
class LinkerPleaseInclude
{
public void Include(ICommand command)
{
command.CanExecuteChanged += (s, e) =>
{
if (command.CanExecute(null))
{
command.Execute(null);
}
};
}
public void Include(MvxListView listview)
{
listview.ItemsSource = new List<int>();
var itemsSource = listview.ItemsSource;
}
public void Include(AnimalSearchViewModel viewmodel)
{
viewmodel.FilteredAnimals = new List<AnimalListInfoViewModel>();
}
}
AnimalSearchViewModel
public class AnimalSearchViewModel : ViewModelBase
{
private string searchString;
private MvxCommand<AnimalListInfoViewModel> itemSelectedCommand;
private readonly IUserDialogs userDialogs;
private readonly IAnimalsStorage animalsStorage;
private readonly IMapper mapper;
private readonly IDebug logger;
public IEnumerable<Animal> Animals { get; set; }
public IList<AnimalListInfoViewModel> FilteredAnimals { get; set; }
public string SearchString
{
get
{
return this.searchString;
}
set
{
this.FindResults(value);
}
}
public IMvxCommand ItemSelectedCommand
{
get
{
this.itemSelectedCommand = this.itemSelectedCommand ?? new MvxCommand<AnimalListInfoViewModel>(this.DoSelectItem);
return this.itemSelectedCommand;
}
}
public AnimalSearchViewModel(
IMvxMessenger messenger,
IUserDialogs dialogs,
IAnimalsStorage animalsStorage,
IMapper mapper,
IDebug logger)
: base(messenger, "Dierkaart")
{
this.userDialogs = dialogs;
this.animalsStorage = animalsStorage;
this.mapper = mapper;
this.logger = logger;
}
public void DoSelectItem(AnimalListInfoViewModel item)
{
this.ShowViewModel<AnimalListInfoViewModel>(new { id = item.Id });
this.logger.LogInfo(DebugTag.Core, "Key: " + item.Key + " Value: " + item);
}
protected override async void InitFromBundle(IMvxBundle parameters)
{
this.Animals = await this.animalsStorage.GetAnimalsAsync();
base.InitFromBundle(parameters);
}
private void FindResults(string keyword)
{
this.searchString = keyword;
if (this.searchString.Length >= 3)
{
var filteredAnimals = this.Animals.Where(i =>
{
// TODO: Get real displayvalue
var displayValue = i.Key;
return displayValue.IndexOf(this.searchString, StringComparison.OrdinalIgnoreCase) != -1;
}).ToArray();
this.FilteredAnimals = this.mapper.Map<List<AnimalListInfoViewModel>>(filteredAnimals);
}
else
{
this.FilteredAnimals = new List<AnimalListInfoViewModel>();
}
}
}
layoutfile:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="?android:attr/actionBarSize"
android:fitsSystemWindows="true">
<EditText
android:id="@+id/search"
android:layout_width="fill_parent"
android:layout_height="@dimen/md_list_single_line_with_avatar_item_height"
android:paddingLeft="@dimen/md_list_item_horizontal_edges_padding"
android:paddingRight="@dimen/md_list_item_horizontal_edges_padding"
android:layout_alignParentTop="true"
android:drawableLeft="@android:drawable/ic_menu_search"
android:inputType="number"
android:singleLine="true"
android:hint="Type om te zoeken..."
local:MvxBind="Text SearchString"/>
<Mvx.MvxListView
android:id="@+id/select_list"
android:scrollbars="vertical"
android:layout_below="@id/search"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
local:MvxBind="ItemsSource FilteredAnimals; ItemClick ItemSelectedCommand"/>
</RelativeLayout>
我可以想象ItemsSource FilteredAnimals會被填充,但這不是在發佈模式下工作..請幫助我。
您是否在使用'Sdk Assemblies Only'或'Sdk and User Assemblies'選項進行鏈接? – Plac3Hold3r
@ Plac3Hold3r SDK Assemblies Only :) – Baklap4