C# MVVMCross发布生成不工作(LinkerPleaseInclude Listview)
当我在调试模式下构建时,一切正常。在版本中构建时,不会填充my MvxListView 这与链接器和MvvmCross执行反射魔法有关,因此链接器不知道将绑定链接到何处 他们说有一个名为“LinkerPleaseInclude.cs”的文件可以帮助伪造绑定作为引用 不知何故,我的listview仍然没有填充。。请帮帮我 Linkerpleaseinclude文件:C# MVVMCross发布生成不工作(LinkerPleaseInclude Listview),c#,android,xamarin,linker,mvvmcross,C#,Android,Xamarin,Linker,Mvvmcross,当我在调试模式下构建时,一切正常。在版本中构建时,不会填充my MvxListView 这与链接器和MvvmCross执行反射魔法有关,因此链接器不知道将绑定链接到何处 他们说有一个名为“LinkerPleaseInclude.cs”的文件可以帮助伪造绑定作为引用 不知何故,我的listview仍然没有填充。。请帮帮我 Linkerpleaseinclude文件: class LinkerPleaseInclude { public void Include(ICommand comma
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>();
}
}
class LinkerPleaseInclude
{
public void Include(ICommand命令)
{
command.CanExecuteChanged+=(s,e)=>
{
if(command.CanExecute(null))
{
command.Execute(null);
}
};
}
public void Include(MvxListView listview)
{
listview.ItemsSource=新列表();
var itemsSource=listview.itemsSource;
}
public void Include(AnimalSearchViewModel视图模型)
{
viewmodel.filteredianmals=新列表();
}
}
动物研究视图模型
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>();
}
}
}
公共类AnimalSearchViewModel:ViewModelBase
{
私有字符串搜索字符串;
私有MvxCommand itemSelectedCommand;
专用只读IUserDialogs用户对话框;
私有只读IAnimalsStorage animalsStorage;
专用只读IMapper映射器;
私有只读IDebug记录器;
公共IEnumerable动物{get;set;}
公共IList筛选器数据{get;set;}
公共字符串搜索字符串
{
得到
{
返回此.searchString;
}
设置
{
此.FindResults(值);
}
}
公共IMvxCommand项SelectedCommand
{
得到
{
this.itemSelectedCommand=this.itemSelectedCommand??新的MvxCommand(this.doselectedItem);
返回此.itemSelectedCommand;
}
}
公共动物搜索视图模型(
IMVX信使,
IUserDialogs对话框,
动物储藏室动物储藏室,
IMapper映射器,
IDebug记录器)
:基地(信使,“迪尔卡尔特”)
{
this.userDialogs=对话框;
this.animalstorage=animalstorage;
this.mapper=mapper;
this.logger=记录器;
}
公共无效DoSelectItem(AnimalListInfoViewModel项)
{
ShowViewModel(新的{id=item.id});
this.logger.LogInfo(DebugTag.Core,“Key:+item.Key+”值:+item);
}
受保护的重写异步void InitFromBundle(IMvxBundle参数)
{
this.Animals=等待this.animalstorage.getanimalasync();
base.InitFromBundle(参数);
}
私有void FindResults(字符串关键字)
{
this.searchString=关键字;
如果(this.searchString.Length>=3)
{
var filteredianmals=this.Animals.Where(i=>
{
//TODO:获取真正的显示值
var displayValue=i.键;
返回displayValue.IndexOf(this.searchString、StringComparison.OrdinalIgnoreCase)!=-1;
}).ToArray();
this.filteredianmals=this.mapper.Map(filteredianmals);
}
其他的
{
this.filteredianmals=新列表();
}
}
}
布局文件:
<?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将被填充,但这在发布模式下不起作用。。请帮助我。我怀疑您在
LinkerPleaseInclude
中的代码只生成了对项目资源
属性的集
访问器的引用。您还需要一个对get
的引用,以避免它被链接出来
试试这个:
public void Include(MvxListView listview)
{
listview.ItemsSource = new List<int>();
var itemsSource = listView.ItemsSource;
}
public void Include(MvxListView listview)
{
listview.ItemsSource=新列表();
var itemsSource=listView.itemsSource;
}
我认为这个问题与您的MvxListView
没有直接关系,而是与您的EditText
中的文本更改有关。如果输入的值没有返回到ViewModel,它将不会触发FindResult(字符串关键字)
并更新列表Filteredianmals
您可以将PostTextChanged
事件添加到LinkerPleaseInclude
中,以防止链接器将其剥离
public class LinkerPleaseInclude
{
public void Include(TextView text)
{
text.AfterTextChanged += (sender, args) => text.Text = "" + text.Text;
text.Hint = "" + text.Hint;
}
}
您是否仅使用
Sdk程序集
或Sdk和用户程序集
选项进行链接?@Plac3Hold3r Sdk程序集:)这是成功的关键!但我仍然在想。。我正在使用EditText作为搜索栏。。为什么我要使用包含文本视图?@Baklap4,您也可以使用EditText
。这只是因为EditText
继承了TextView
,所以在最低基类上链接将保证所有继承类的属性/事件不会被链接出来。感谢您的解释!