Adding an Effect to an Xamarin.Forms Frame does not call OnAttached().
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ResolutionGroupName("EffectOnFrame")]
[assembly: ExportEffect(typeof(EffectOnFrame.Droid.DemoEffectDroid), "DemoEffect")]
namespace EffectOnFrame.Droid
{
public class DemoEffectDroid : PlatformEffect
{
protected override void OnAttached() => System.Console.WriteLine("Attached");
protected override void OnDetached() => System.Console.WriteLine("Detached");
}
}
using System;
using Xamarin.Forms;
namespace EffectOnFrame
{
public class App : Application
{
public App()
{
var view = new Frame();
view.Effects.Add(Effect.Resolve("EffectOnFrame.DemoEffect"));
MainPage = new ContentPage { Content = view };
}
}
}
When launching the App the OnAttached() method should be called.
The Effect is not called properly when view is a Frame. If using a Label, StackLayout or ContentView the Effect is called properly.
Yep. As reported. No logging for frame but'll work for label.
I made a PR to fix this issue : #4195
Two possible workarounds :
protected override void OnElementChanged(ElementChangedEventArgs<Frame> e)
{
base.OnElementChanged(e);
VisualElement oldElement = e.OldElement;
IElementController controller = oldElement;
if (controller != null && controller.EffectControlProvider == this)
controller.EffectControlProvider = null;
controller = e.NewElement;
if (controller != null)
controller.EffectControlProvider = this;
}
Almost a year has passed and this is still an issue...Are there any plans to fix it?
This is still an issue in v3.6.0.
Which version can I expect this release?
@KalyanXamarin this is already available from 4.1 onwards
Just upgraded to Xamarin Forms 4.6.0.800 (from 4.5) and it seems this issue has resurfaced as my PlatformEffect that's attached to a Frame (inside the ItemTemplate of a CollectionView) is no longer attaching. When i move the effect to the Grid that's contained inside the Frame, it then works as expected.
Most helpful comment
Just upgraded to Xamarin Forms 4.6.0.800 (from 4.5) and it seems this issue has resurfaced as my PlatformEffect that's attached to a Frame (inside the ItemTemplate of a CollectionView) is no longer attaching. When i move the effect to the Grid that's contained inside the Frame, it then works as expected.