Forms 获取listview的bindingContext';数据模板中的页面
我想将DataTemplate(它是一个viewCell)中的一个按钮绑定到listView页面的viewModel(它是bindingContext页面的ofc)命令。 我把模板放在另一个文件中,因为我想在其他地方重用它。这是主要问题 这是我的页面中的列表视图Forms 获取listview的bindingContext';数据模板中的页面,forms,xamarin,binding,command,datatemplate,Forms,Xamarin,Binding,Command,Datatemplate,我想将DataTemplate(它是一个viewCell)中的一个按钮绑定到listView页面的viewModel(它是bindingContext页面的ofc)命令。 我把模板放在另一个文件中,因为我想在其他地方重用它。这是主要问题 这是我的页面中的列表视图 _timeLineListView = new MR.Gestures.ListView { RowHeight = 230, Separato
_timeLineListView = new MR.Gestures.ListView
{
RowHeight = 230,
SeparatorVisibility = SeparatorVisibility.None,
ItemTemplate = new DataTemplate(typeof(TimeLineScheduleComponent)),
BackgroundColor = Color.FromHex("0D2E383F")
};
listView的ItemSource绑定到viewModel的属性
在TimeLineSchedule组件中,我有一个按钮:
_acceptScheduleButton.SetBinding(MR.Gestures.Button.TappedCommandProperty, "ToLastStepTradeCommand");
_acceptScheduleButton.BindingContext = ParentBindingContext;
下面是页面的viewModel,其中包含我要绑定到的命令:
/// <summary>
/// Command schedule button
/// </summary>
public Command ToLastStepTradeCommand
{
get
{
return new Command(() =>
{
});
}
}
在页面上,我做了如下操作:
var test = new DataTemplate(typeof(TimeLineScheduleComponent));
test.SetBinding(TimeLineScheduleComponent.ParentBindingContextProperty, new Binding(BindingContextProperty.PropertyName));
test.BindingContext= this; //this is wrong I know ...
但不起作用,我认为最后一部分(我应该给我的测试数据模板提供哪个绑定上下文?)有问题。我使用纯c语言,找到了一些xaml解决方案,但很难翻译
谢谢
var test = new DataTemplate(typeof(TimeLineScheduleComponent));
test.SetBinding(TimeLineScheduleComponent.ParentBindingContextProperty, new Binding(BindingContextProperty.PropertyName));
test.BindingContext= this; //this is wrong I know ...