Template property:
public StackLayout Template
{
get
{
if (_template != null)
RemoveBehaviors(_template);
_template = CreateTemplate(this);
return _template;
}
set
{
_template = value;
}
}
RemoveBehavior method: /// <summary>
/// Removes behavior of child view if any
/// </summary>
/// <param name="parent"></param>
private void RemoveBehaviors(Xamarin.Forms.View parent)
{
if (parent != null)
{
parent.Behaviors.Clear();
var viewGroup = parent as Xamarin.Forms.Layout<Xamarin.Forms.View>;
var contentView = parent as ScrollView;
if (viewGroup != null)
{
foreach (Xamarin.Forms.View view in viewGroup.Children)
RemoveBehaviors(view);
}
else if (contentView != null)
{
contentView.Content.Behaviors.Clear();
RemoveBehaviors(contentView.Content);
}
}
}
|