Forum Xamarin.Forms

Behaviors and ControlTemplate in application resources

I have defined a ControlTemplate in the application resources:

<Application ...>
            <ControlTemplate x:Key="mytemplate">
                <!-- template content here -->
                <ContentPresenter ... />

Inside the template, there is an ImageButton with an associated Behavior:

<ImageButton ...>
        <H:MyButtonBehavior />

Then, I have created different pages based on this template:

<ContentView ControlTemplate="{StaticResource mytemplate}" >
    _page code here_

In the MyButtonBehavior class, the OnAttachedTo methos is properly called when the behavior is attached to the control.

Now, the question: how can I detach the behavior from the control?

I should call something like myimagebuttonref.Behaviors.Clear(), but I cannot understand how to get a reference to the control.

Any help is appreciated, thank you!

Sign In or Register to comment.