Moving an object relative to its current location in Expression Blend - animation

I am new to Expression Blend 4 but am having a problem with something quite simple.
I would like a button to move an object up by 20px whenever the button is clicked. I followed a tutorial here that suggests if you use a storyboard animation (with no keyframe at the start) that moves the object then it will play the animation, moving it as planned from wherever the object currently is (ie: continue to move up each time pressed) however when I try this, the animation only works the once.
I have tried ticking the 'use relative values' box in the transform menu but it makes no difference.
Am I missing something obvious?

NOTE: the point values I'm referring to here are relative to the object's original location and not specific point values.
I think the issue is that the Storyboard, while it has played all the way through, has not actually stopped. When you establish the end point of (-20,-20), that is relative to it's beginning point. Playing the animation again (assuming no keyframe at time zero) will move the object from it's existing location (-20,-20) to the target location which is also (-20,-20). This gives the appearance of no animation which is technically not accurate. If you had a separate animation with no keyframe at zero that moved the same object it would begin from wherever the object happens to be to the first keyframe in the animation.
If you actually Stop the animation the object will return to it's original value at (0,0). Test this by adding a different Button that issues a Stop [I use the ControlStoryboardAction behavior for this]. Here is a sample you can use to test this:
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
mc:Ignorable="d"
x:Class="Animation1.MainPage"
Width="640"
Height="480">
<UserControl.Resources>
<Storyboard x:Name="Storyboard1">
<DoubleAnimation Duration="0:0:0.8"
To="-20"
Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)"
Storyboard.TargetName="rectangle"
d:IsOptimized="True" />
<DoubleAnimation Duration="0:0:0.8"
To="-20"
Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)"
Storyboard.TargetName="rectangle"
d:IsOptimized="True" />
</Storyboard>
</UserControl.Resources>
<Grid x:Name="LayoutRoot"
Background="White">
<Button Content="Play"
HorizontalAlignment="Left"
Height="37"
Margin="35,53,0,0"
VerticalAlignment="Top"
Width="65">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<ei:ControlStoryboardAction Storyboard="{StaticResource Storyboard1}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
<Rectangle x:Name="rectangle"
Fill="#FF0303FF"
Height="99"
Margin="275,0,207,57"
Stroke="Black"
VerticalAlignment="Bottom"
RenderTransformOrigin="0.5,0.5">
<Rectangle.RenderTransform>
<CompositeTransform />
</Rectangle.RenderTransform>
</Rectangle>
<Button Content="Stop"
HorizontalAlignment="Left"
Height="40"
Margin="35,115,0,0"
VerticalAlignment="Top"
Width="65">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<ei:ControlStoryboardAction ControlStoryboardOption="Stop"
Storyboard="{StaticResource Storyboard1}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
</Grid>
I think you are going to have to approach this particular problem differently. The easiest would be to place this in a Canvas and manage the Top and Left values (preferably through a binding). The idea would be to capture the storyboard completion and update the values in the binding and then Stop the animation. This should give the correct starting point for the next time the animation is Played. Sorry I don't have time to put this together, but hopefully this will get you farther along.

Related

Xamarin Forms Shapes inside SwipeView not working consistently

I created a solution (see code here) from a blank Xamarin Forms template, running the latest stable version of Xamarin Forms. I added the experimental Shapes and SwipeView as required into my native projects, and I have a list of rows just saying "Hello" inside a Collection View.
I attempted to add a semicircle shape to the right swipe item's Grid, so it looks like the row has a rounded edge instead of rectangular shape.
But as you can see in the image below, the Shape just disappears after swiping to the right the second time. And occasionally the shape won't even appear in the row's swipe item.
Please note that the label always displays though, its just the shape going away. Also tested in Android & noticed the same behaviour. Do you know what the issue might be and if there's a work around?
Edit: Posted this and got a response to create an issue. Still looking for a workaround though
You can use Frame with CornerRadius to achieve the result:
<StackLayout Orientation="Horizontal" Padding="0" Margin="0" Spacing="0">
<Label
Text="Left"
HorizontalOptions="CenterAndExpand"
VerticalOptions="CenterAndExpand" />
<!--<Path HorizontalOptions="EndAndExpand" Fill="White" Stroke="White" Aspect="Fill" Data="m0.19956,-0.20844l14.43749,0l0,0c7.97347,0 14.43748,6.51981 14.43748,14.56254c0,8.04265 -6.464,14.5625 -14.43748,14.5625l-14.43749,0l0,-29.12504z" >
<Path.RenderTransform>
<RotateTransform CenterX="14.637"
CenterY="14.3541"
Angle="180" />
</Path.RenderTransform>
</Path>-->
<Frame BackgroundColor="Yellow" CornerRadius="30" IsClippedToBounds="True" HeightRequest="30" WidthRequest="30" HorizontalOptions="End" Margin="0,0,-51,0">
</Frame>
</StackLayout>

Putting together image pan, zoom and rotation (C#, XAML)

I want to display images that the user has provided. These images are likely to be larger than the screen resolution (so need zoom and pan capability) plus the image may not be orientated correctly for the screen (so need to be able to rotate).
Implementing pan and zoom seems to be somewhat straightforward:
<ScrollViewer HorizontalSnapPointsType="None" HorizontalScrollBarVisibility="Auto" VerticalSnapPointsType="None" ZoomSnapPointsType="None" IsHorizontalRailEnabled="False" IsVerticalRailEnabled="False" ManipulationMode="All" VerticalScrollBarVisibility="Auto">
<Image x:Name="pannableImage" Source="{Binding FullSizedImage}" AutomationProperties.Name="{Binding Title}" />
</ScrollViewer>
This works well and meets my needs, although I would like to be able to set the initial zoom factor so that if the image is larger than the screen, the zoom factor is set so that it fills the screen and if the image isn't larger than the screen, the zoom factor is set so that the image is shown at its full size, i.e. not zoomed in.
However, I'm struggling to get rotation to work acceptably. I've tried this:
<ScrollViewer HorizontalSnapPointsType="None" HorizontalScrollBarVisibility="Auto" VerticalSnapPointsType="None" ZoomSnapPointsType="None" IsHorizontalRailEnabled="False" IsVerticalRailEnabled="False" ManipulationMode="All" VerticalScrollBarVisibility="Auto">
<Image x:Name="pannableImage" Source="{Binding FullSizedImage}" AutomationProperties.Name="{Binding Title}" >
<Image.Projection>
<PlaneProjection RotationZ="{Binding ImageRotation}"/>
</Image.Projection>
</Image>
</ScrollViewer>
Although this does rotate the image, the problem is that the ScrollViewer then gets the scrolling wrong. I've also tried putting the Projection onto the ScrollViewer instead of the Image and that is even worse.
Putting the project onto the image seems to make the most sense since the ScrollViewer should then get the dimensions of the projected image but that doesn't quite seem to be the case.
What am I misunderstanding here, please?
Thanks.
Philip
The solution was to use a RenderTransform instead of a Projection:
<Image x:Name="pannableImage" Source="{Binding FullSizedImage}" ManipulationMode="All" Loaded="pannableImage_Loaded" IsDoubleTapEnabled="False" IsHitTestVisible="False" IsHoldingEnabled="False" IsRightTapEnabled="False" IsTapEnabled="False" ScrollViewer.VerticalScrollBarVisibility="Disabled" LayoutUpdated="pannableImage_LayoutUpdated">
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform x:Name="Scale" />
<RotateTransform x:Name="Rotate" />
<TranslateTransform x:Name="Translate" />
</TransformGroup>
</Image.RenderTransform>
</Image>

Adding tiles in the panorama page

Can we add tiles in one of the sections in panorama or i need to implement it using button(changing the style of the button, so that it appears like a tile)
There is no tile control, so you'll have to create your own. You can do this by styling a button, like you said, or using an Image control.
There is no framework control that gives a tile layout. However, it is very easy to template Buttons so that they are simply rectangular squares of colour, allowing you to use them as tiles:
<DataTemplate x:Key="TileTemplate">
<Button Width="160" Height="160"
Margin="10">
<Grid>
<Rectangle Fill="{StaticResource PhoneAccentBrush}"/>
<ContentPresenter Content="{TemplateBinding Content}"/>
</Grid>
</Button>
</DataTemplate>
You can then host them within a Silverlight Toolkit WrapPanel
This is an old post, but a project does now exist. Take a look at the TileSlider project

Custom Template in PushPin

Howdy,
I want to generate several location of pushpins on a seperate layer over a map. Those PushPins shall represent places at this very coordinate. Thus they should show some additional information which should be visible once the user taps/touches the Pushpin.
This whole solution is solely code based ( adding of the pushpins ).
I already here on sa that I should put an invisible button behind the pushpins - but I'm not quite sure how I should do that.
It would be great if somebody has a hint which'll bring me forward!
Thanks
<DataTemplate x:Key="PushpinControlTemplate2">
<Grid x:Name="ContentGrid">
<StackPanel Orientation="Vertical">
<Grid Background="{TemplateBinding Background}"
HorizontalAlignment="Left"
MinHeight="10"
MinWidth="29">
<Hyperlinkbutton HorizontalAlignment="Center" Content="{binding}" Click="clicker" Margin="0"/>
</Grid>
<Polygon Fill="{TemplateBinding Background}"
Points="0,0 29,0 0,29"
Width="29"
Height="29"
HorizontalAlignment="Left"/>
</StackPanel>
</Grid>
</DataTemplate>
This is my code which I use so far, the function clicker is defined, however I always the error 'AG_E_PARSER_BAD_PROPERTY_VALUE [Line: 5 Position: 98]'
This Pushpin-Styles in Bing Maps for the Windows Phone post should tell you everything you need to know about styling pushpins.

Windows Phone 7 Image Button

I need to create an Image Button for my application like web-oriented style.
I have an image 20x20 pixel and want an image button with the same dimension of the image.
I tried to set this inside my xaml but it doesn't work:
<Button Grid.Row="0" Margin="0" Padding="0" Click="AddtoFavorite_Click" Width="20" Height="20" VerticalAlignment="Top" HorizontalAlignment="Right">
<Button.Content>
<Image Source="/MyNamespace;component/images/star_yellow.png" Margin="0" Width="20" Height="20" />
</Button.Content>
</Button>
What is wrong?
SOLUTION
I found the best solution is:
<Image Source="/MyNamespace;component/images/star_yellow.png" ManipulationStarted="Image_ManipulationStarted" Width="20" Height="20"></Image>
Thanks to all!
I don't see particular errors in your code but I don't have the tools right now to test it ans see why it fails.
However you can create a VisualBrush with your image and use it as background for your Button:
<Button>
<Button.Background>
<ImageBrush ImageSource="xyz.png"/>
</Button.Background>
</Button>
Most Backgrounds are of type Brush, so you can use SolidColorBrush, LinearGradientBrush, ImageBrush, etc. You are not limited to colors.
I think the best solution is the following:
<Button ...>
<Button.Template>
<ControlTemplate>
<Image .... />
</ControlTemplate>
</Button.Template>
</Button>
Using manipulation started will result in subtly non-standard behaviour. On most buttons if you click on it but then drag off, the button click will not fire. However, if you use ManipulationStarted it will fire immediately.
The best way to manage these design time considerations is to use Expression Blend. In blend you can right click on the button and edit the template through the design tools, which makes knowing how to edit the xaml less important. It's really worth the effort to learn to use Blend.
This is old but I thought I would offer what I thought was a better solution here. Some of these solutions want you to replace the button with an image, or the background with an imagebrush. That's fine except it also surrounds the image with the normal button style, a black or white box (depending on your theme).
This solution lets you use an image as the button itself while maintaining the complete fidelity of a button but without having to subclass an object like the link by SilverGeek.
First, create a new style (either in your App.xaml or your page resources)
<Style x:Key="ImageButtonStyle" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<Image x:Name="StartButtonImage" Source="/Images/YourImageFile.png"/>
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Content=""/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
Now, just create a button anywhere using that style:
<Button Style={StaticResource ImageButtonStyle}/>
And add click events or whatever else you want. The button will take on the entire style of the image.
Maybe you will be interested in this article:
http://silvergeek.net/2011/01/14/imagebutton-control-for-win-phone-7/
The Button control can take most controls as its content (not just text), so you don't need an "image button" - instead, you simply need to put an Image control inside your Button like so:
<Button>
<Image Source="http://www.richmondwiki.org/images/search-button.png"></Image>
</Button>
This approach (as opposed to using an ImageBrush for the Button background) means that you don't have to worry about or hardcode the sizes of the Image/Button - WP7 will handle this for you.
Using the provided Button control instead of hooking into the manipulation events is recommended, so that you won't have to worry about things like having appropriate margins for touch targets, etc.
You can set your image as the background for the button, or if you want to do it as content, in theory it should work inside a stackpanel.
You don't even need to use a Button.
You can hook the MouseLeftButtonUp event on the Image control.
<Image
Source='blue02.png'
Width='26'
Height='26'
Margin='5'
MouseLeftButtonUp='Image_MouseLeftButtonUp' />

Resources