Virginia Lopez
Virginia Lopez

Reputation: 23

Is it possible to add a TiltEffect programmatically?

I have some images that I add programmatically depending on the selection of a listpicker. I´ve been able to add tap events to those images in the .cs and now I´m looking if there´s a way to add the tiltEffect by code too.

Does anybody know if it´s possible and how to do it?

Thanks.

Upvotes: 1

Views: 292

Answers (2)

You simply add this line of code

TiltEffect.SetIsTiltEnabled(<UIobject>, true);

Sample:

Button MyButton = new Button() { Content = "I have Tilt effect!!" };
TiltEffect.SetIsTiltEnabled(MyButton, true);

Upvotes: 1

Olivier Payen
Olivier Payen

Reputation: 15268

The Button control can take most controls as its content (not just text), so you don't need to fake your image as a button, instead, you simply need to put an Image control inside your Button like so:

<Button BorderThickness="0">
    <Image Source="/image.jpg"/>
</Button>

or programmatically:

Button myButton = new Button();
Image img = new Image();
myButton.BorderThickness = new Thickness(0);
myButton.Content = img;

Using the default Button control instead of hooking into the image tap events is recommended, so that you won't have to worry about things like having appropriate margins for touch targets, etc.

The other advantage of using the Button control is that the Tilt Effect will work directly (you just need to have the toolkit:TiltEffect.IsTiltEnabled="True" in your Page).

Upvotes: 0

Related Questions