【发布时间】:2018-09-14 03:15:37
【问题描述】:
我已经关注了几个关于在 Xamarin.Forms 中使用本机视图的教程,但是我没有成功将命令绑定到从 ViewModel 到本机视图。
下面是android中自定义Native控件的代码:
public class MyFAB : FloatingActionButton
{
public Command Command { get; set; }
public MyFAB (Context context) : base(context)
{
this.SetImageResource(Resource.Drawable.ic_add_white_24dp);
Click += (sender, e) =>
{
Command?.Execute(null);
};
}
}
这是 Xaml 代码:
<droidCustom:AddFAB x:Arguments="{x:Static formsDroid:Forms.Context}" UseCompatPadding="true" Command="{Binding AddCategoryCommand}"
AbsoluteLayout.LayoutBounds="1,1,AutoSize,AutoSize" AbsoluteLayout.LayoutFlags="PositionProportional"/>
视图正确显示,但命令未触发,当我调试时,命令从未分配,它始终为空。 当我在线浏览博客文章时,他们说命令绑定不需要任何可绑定属性......但在这里我仍然遇到问题。
【问题讨论】:
标签: c# xaml xamarin binding xamarin.forms