Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

Behaviors and ControlTemplate in application resources

$
0
0

I have defined a ControlTemplate in the application resources:

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

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

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

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

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

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!


Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>