Windows Phone 7_EventTrigger - silverlight

I'm working with Windows Phone 7. When I use the EventTrigger for TextBlock as below:
<TextBlock Foreground="White" FontWeight="Bold" x:Name="txt" Text="199" Height="100">
<TextBlock.Triggers>
<EventTrigger RoutedEvent="TextBlock.MouseMove" >
<BeginStoryboard>
<Storyboard>
<DoubleAnimation AutoReverse="True" Duration="0:0:1"
From="1.0" RepeatBehavior="Forever"
Storyboard.TargetName="txt"
Storyboard.TargetProperty="Opacity"
To="0.0"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</TextBlock.Triggers>
</TextBlock>
If I have RoutedEvent="TextBlock.Loaded" that is no problem, but another event(MouseMove, Click...) it will fail with the error "Attribute TextBlock.MouseMove value is out of range".
What is the problem?
Thanks a lot.

Firstly "MouseMove" and "Click" don't apply on a phone as there is no mouse!
Secondly, you may want to check the remarks in the docs on MSDN:
The only supported value in Silverlight is Loaded/FrameworkElement.LoadedEvent.

Related

Animation triggering on property change doesn't seem to fire

I'm trying to make a status textblock that will display things like "Database updated" and other information for which a dialog would be overkill. It should flash on the screen and then fade away within 2 seconds or so. The goal is that it will sit at opacity 0 until its binding is updated, then 1 opacity and fade out. Problem is, what I came up with doesn't seem to trigger at all. Here's my code:
<TextBlock Text="{Binding AppState.Feedback}" x:Name="feedbackBlock"
Opacity="0" FontSize="100" Foreground="Black">
<TextBlock.Triggers>
<EventTrigger RoutedEvent="Binding.TargetUpdated">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="feedbackBlock"
Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:2" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</TextBlock.Triggers>
</TextBlock>
Not really sure where to start in debugging this, I don't get an error, it just doesn't show.
You haven't told the Binding to fire the TargetUpdated event. Add NotifyOnTargetUpdated=True to the Binding expression. Besides that, you don't need to set Storyboard.TargetName:
<TextBlock x:Name="feedbackBlock"
Text="{Binding AppState.Feedback, NotifyOnTargetUpdated=True}"
Opacity="0" FontSize="100" Foreground="Black">
<TextBlock.Triggers>
<EventTrigger RoutedEvent="Binding.TargetUpdated">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity"
To="1" Duration="0:0:2" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</TextBlock.Triggers>
</TextBlock>

How to enlarge an Ellipse in WPF?

How i can enlarge an Ellipse in WPF, preffering using Margins, just like i did in my wrong code :D ? how i can do that, you will understand from the "wrong code"
<DoubleAnimation Duration="00:00:01" Storyboard.TargetProperty="Margin" From="789,-189,762,899" To="23,-189,-4,-637"/>
http://i.stack.imgur.com/Ryn31.png
Use ThicknessAnimation instead of DoubleAnimation :)
I tried enlarging an Ellipse by altering Margin values but did not see any visual change.
I see this question already has been answered, in any case, here is an example of how it is possible to animate the height and Width of an Ellipse in WPF using markup in XAML:
<Ellipse Height="100" Width="100" Fill="Blue" Stroke="Black">
<Ellipse.Triggers>
<EventTrigger RoutedEvent="Loaded">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation RepeatBehavior="Forever" Storyboard.TargetProperty="Width" From="100" To="300" Duration="00:00:02" />
<DoubleAnimation RepeatBehavior="Forever" Storyboard.TargetProperty="Height" From="100" To="300" Duration="00:00:02" />
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Ellipse.Triggers>
</Ellipse>

XamlParseException occured - animating an ellipse

I have the following code to animate the width of the ellipse forever until the window is closed. However, it throws XamlParseExceptionError. Could someone point out to me where I made the mistake?
`
</TextBlock>
<TextBlock x:Uid="ProductName" Localization.Attributes="$Content(Readable Unmodifiable)">
<TextBlock.ToolTip>
<TextBlock x:Uid="ProductNameTip" Localization.Attributes="$Content(ToolTip Readable Modifiable)">
A photo editor that will make everyone look beautiful
</TextBlock>
</TextBlock.ToolTip>
Amazing Photo Editor
</TextBlock>
<Ellipse Name="Circle"
Width="100"
Height="100"
Fill="Red">
<Ellipse.Triggers>
<EventTrigger RoutedEvent="Ellipse.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.Target="Circle"
Storyboard.TargetProperty="Width"
From="1"
To="100"
Duration="0:0:5"
AutoReverse="True"
RepeatBehavior="Forever">
</DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Ellipse.Triggers>
</Ellipse>
</StackPanel>
</Grid>
`
Use Storyboard.TargetName Attached Property instead of Storyboard.Target.
<DoubleAnimation Storyboard.TargetName="Circle"

Textbox Text-Color Animation

Is it possible to animate just the part of the value of textbox/label. For example, txt1.text = "This is a Sample";. then I want to animate the word "Sample" to change its color/opacity etc. If you get what i mean. If it is possible please demonstrate the code Thanks!
I think you can't do it with a TextBox as its text has no formatting options. Not sure if the Label allows it, but the TextBlock might help you:
<TextBlock>
<TextBlock.Triggers>
<EventTrigger RoutedEvent="Loaded">
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetName="scb01"
Storyboard.TargetProperty="Color"
From="White"
To="Black"
Duration="0:0:0.5"
AutoReverse="True"
RepeatBehavior="Forever" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</TextBlock.Triggers>
One <Run>
<Run.Foreground>
<SolidColorBrush x:Name="scb01"
Color="Red" />
</Run.Foreground>
Two</Run> Three
</TextBlock>

Can't assign RoutedEvent to Binding.TargetUpdated

I have a textblock which should react for changing its text (it must display text for few seconds, and then dissapear).
<TextBlock Text="{Binding Path=OperationMessage, NotifyOnValidationError=True}" x:Name="label_OperationMessage" Visibility="Collapsed" HorizontalAlignment="Right" Margin="3,3,3,3" >
<TextBlock.Triggers>
<EventTrigger RoutedEvent="Binding.TargetUpdated">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="0:0:0" To="1.0" />
<DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="0:0:2" From="1.0" To="0.0" BeginTime="0:0:5" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</TextBlock.Triggers>
</TextBlock>
When I launch my app I get error :
Failed to assign to property 'System.Windows.EventTrigger.RoutedEvent'.
on the line
<EventTrigger RoutedEvent="Binding.TargetUpdated">
What is wrong with this code?
The only event supported by Silverlight for use in the Triggers property is the Loaded event. Anything else will result in this exception.
To acheive this sort of Xaml event logic you can download the Blend SDK which contains all manner of useful features like this. In your case you are looking for the PropertyChangedTrigger.

Resources