The reason why my Make text appear and disappear in Silverlight 2 didn't work anymore after some Silverlight updates is because I used the Mouse Down event on the button. After the update the correct way of making a button work is the Click event. The Mouse Down event works with shapes and other objects such as this rectangle:

Update 2009-01-07: After grahamws' comment I have added to the button and the rectangle animations a text affected by the Visibility property. In its normal state it's Collapsed and it is set at Visible in a 2 second timeline. This to show that now in Silverlight 2 Release the Visibility property works fine unlike at the time when I played with it in a previous Silverlight version.

You can see all the code in my comment from 2009/01/07.

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Related posts

Comments

geekswithblogs.net

Thursday, September 04, 2008 5:44 AM

Pingback from geekswithblogs.net

Silverlight Cream for September 04, 2008 -- #361

mgalinks.wordpress.com

Thursday, September 04, 2008 4:49 PM

Pingback from mgalinks.wordpress.com

2008 September 05 - Links for today « My (almost) Daily Links

grahamsw us

Tuesday, January 06, 2009 2:10 PM

Is the source for this available? I think I'm missing something...

Silverlight Girl

Tuesday, January 06, 2009 9:49 PM

Hi Graham, here is the xaml that includes the addition I just did of the Visibility animation. (See update on the post) Let me know if you are still missing something. Further down is the .cs code. Cheers!


<UserControl x:Class="TextAppearButtonEventClick.Page"
xmlns="schemas.microsoft.com/.../presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300" xmlns:d="schemas.microsoft.com/expression/blend/2008" xmlns:mc="schemas.openxmlformats.org/.../2006" mc:Ignorable="d">
<UserControl.Resources>
<Storyboard x:Name="TextAppearsandDisappears">
<!--Color animation for "This text will disappear soon"-->
<ColorAnimationUsingKeyFrames Storyboard.TargetName="TextColor" Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)" BeginTime="00:00:00">
<SplineColorKeyFrame KeyTime="00:00:00" Value="#FE7F1566"/>
<SplineColorKeyFrame KeyTime="00:00:02" Value="#FE7F1566"/>
<SplineColorKeyFrame KeyTime="00:00:02.1000000" Value="DeepPink"/>
</ColorAnimationUsingKeyFrames>

<!--Visibility animation for "Visibility: Visible"-->
<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="TextVisibility" Storyboard.TargetProperty="(UIElement.Visibility)">
<DiscreteObjectKeyFrame KeyTime="00:00:00">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime="00:00:02">
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</UserControl.Resources>

<Grid x:Name="LayoutRoot" Background="DeepPink">
<TextBlock x:Name="TextColor" Height="54" Margin="54,62,60,0" VerticalAlignment="Top" TextWrapping="Wrap" FontFamily="Portable User Interface" FontSize="18" FontStretch="Normal" FontStyle="Normal" FontWeight="Normal" Foreground="DeepPink" Text="This text will disappear soon.." d:LayoutOverrides="VerticalAlignment"/>

<TextBlock x:Name="TextVisibility" Margin="120,116,100,143" Visibility="Collapsed" TextWrapping="Wrap"><Run FontSize="18" Text="Visibility: Visible"/></TextBlock>

<Button x:Name="Button" Height="65" Width="150" Margin="59.5,0,190.5,69" Content="Button Event: Click" VerticalAlignment="Bottom" Cursor="Hand" UseLayoutRounding="True" Click="ClickButton" FontSize="11" />

<Grid Width="123" Height="66" Cursor="Hand" MouseLeftButtonDown="RectangleMouseDown" Margin="0,165.5,40,68.5" d:LayoutOverrides="VerticalAlignment, Width" HorizontalAlignment="Right">
<Rectangle Margin="0,0,2,0" Fill="#FFD280E8" Stroke="#FF8C5E97" RadiusX="8" RadiusY="8"/>
<TextBlock Margin="2,9,0,9" FontSize="11" Text="Rectangle Event: 
Mouse Left Button Down" TextAlignment="Center" TextWrapping="Wrap"/>
</Grid>

</Grid>
</UserControl>


and here is the .cs code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace TextAppearButtonEventClick
{
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
}

private void ClickButton(object sender, RoutedEventArgs e)
{
this.TextAppearsandDisappears.Begin();
}

private void RectangleMouseDown(object sender, MouseButtonEventArgs e)
{
this.TextAppearsandDisappears.Begin();
}
}
}

silverlightweb.com.cn

Saturday, October 31, 2009 2:34 AM

Pingback from silverlightweb.com.cn

Fix for: Make test appear and disappear in Silverlight 2 Silverlight Web

Comments are closed