我在Xamarin中定制了渲染器,我想知道如何动态更新它的值。
这是我在主班的控制:
public class MainControl : View
{
public double A
{
get;
set;
}
}
这是我的自定义渲染器,在Android中定义:
[assembly: Xamarin.Forms.ExportRenderer(typeof(MainApplication.MainControl), typeof(MainApplication.Droid.CustomRenderer))]
namespace MainApplication.Droid
{
public class CustomRenderer : ViewRenderer<MainControl,
MainApplication.Droid.ControlAndroid>
{
private ControlAndroid control;
public CustomRenderer(Context context) : base(context)
{
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
}
protected override void OnElementChanged(ElementChangedEventArgs<MainControl> e)
{
base.OnElementChanged(e);
if (Control == null)
{
control = new ControlAndroid(Context);
SetNativeControl(control);
}
}
}
}
方法OneElementChanged仅在创建对象时更新。不会触发OneElementPropertyChanged。
我期望在从主类更改属性A的值时触发一些东西。