I am creating a dashboard in WPF with a bunch of key performance indicators, each of which consists of three values.
Whenever the values change I would like the user control to blink for 5 seconds. I would like to make the background color of the control to switch the foreground color of the textblock, and the textblock foreground color to change to the background color of the user control.
This whole WPF animation is new to me, so any help would be much appreciated!
My user control looks like:
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="10" />
<RowDefinition Height="Auto" />
<RowDefinition Height="10" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock x:Name="TitleTextBlock" Text="Title" FontSize="32" HorizontalAlignment="Center" Grid.Row="0" FontFamily="OCR-A II" Foreground="White" VerticalAlignment="Bottom" />
<TextBlock x:Name="Value1TextBlock" Text="0" FontSize="192" HorizontalAlignment="Center" Grid.Row="2" FontFamily="OCR-A II" VerticalAlignment="Center" Foreground="White" />
<TextBlock x:Name="Value2TextBlock" Text="0" FontSize="32" HorizontalAlignment="Center" Grid.Row="4" FontFamily="OCR-A II" Foreground="White" VerticalAlignment="Top" />
</Grid>
To make a TextBlock blink when its Text Changes you can use ColorAnimationUsingKeyFrames. Text is binding to a property called TextTitle.
<Window.Resources>
<Storyboard x:Key="blinkAnimation" Duration="0:0:5" >
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Background).(SolidColorBrush.Color)"
Storyboard.TargetName="TitleTextBlock"
AutoReverse="True">
<ColorAnimationUsingKeyFrames.KeyFrames>
<DiscreteColorKeyFrame KeyTime="0:0:0" Value="White"/>
<DiscreteColorKeyFrame KeyTime="0:0:1" Value="Black"/>
<DiscreteColorKeyFrame KeyTime="0:0:2" Value="White"/>
<DiscreteColorKeyFrame KeyTime="0:0:3" Value="Black"/>
<DiscreteColorKeyFrame KeyTime="0:0:4" Value="White"/>
</ColorAnimationUsingKeyFrames.KeyFrames>
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)"
Storyboard.TargetName="TitleTextBlock"
AutoReverse="True">
<ColorAnimationUsingKeyFrames.KeyFrames>
<DiscreteColorKeyFrame KeyTime="0:0:0" Value="Black"/>
<DiscreteColorKeyFrame KeyTime="0:0:1" Value="White"/>
<DiscreteColorKeyFrame KeyTime="0:0:2" Value="Black"/>
<DiscreteColorKeyFrame KeyTime="0:0:3" Value="White"/>
<DiscreteColorKeyFrame KeyTime="0:0:4" Value="Black"/>
</ColorAnimationUsingKeyFrames.KeyFrames>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
<Grid Name="grid" Background="Black">
<TextBlock x:Name="TitleTextBlock" Text="{Binding TextTitle, NotifyOnTargetUpdated=True}" FontSize="32" HorizontalAlignment="Center" Grid.Row="0" FontFamily="OCR-A II" Foreground="White" VerticalAlignment="Bottom" Background="Black">
<TextBlock.Triggers>
<EventTrigger RoutedEvent="Binding.TargetUpdated">
<EventTrigger.Actions>
<BeginStoryboard>
<StaticResource ResourceKey="blinkAnimation"/>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</TextBlock.Triggers>
</TextBlock>
</Grid>
This will make the TextBlock blink everytime its Text changes. Note that you must set Background and Foreground explicitly on the TextBlock before using the blinkAnimation, otherwise you'll recieve a System.InvalidOperationException: 'Background' property does not point to a DependencyObject in path '(0).(1)'.
Update
To start this animation from code behind you can do this.
Storyboard blinkAnimation = TryFindResource("blinkAnimation") as Storyboard;
if (blinkAnimation != null)
{
blinkAnimation.Begin();
}
Related
Why the following event triggers of grid MouseEnter/MouseLeave not working. As a workaround, I used IsMouseOver.
There are no errors, binding errors, simply it does not work without any idea what is the reason.
Any Idea?
Just to pass validation
Here is the code
<ItemsControl.ItemTemplate>
<DataTemplate>
<DataTemplate.Resources>
<Storyboard x:Key="OnGrdMouseEnter">
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="Item">
<EasingColorKeyFrame KeyTime="0" Value="#2097B5"/>
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="TimeFrameItemText">
<EasingColorKeyFrame KeyTime="0" Value="White"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="OnGrdMouseLeave">
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="Item">
<EasingColorKeyFrame KeyTime="0" Value="Transparent"/>
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="TimeFrameItemText">
<EasingColorKeyFrame KeyTime="0" Value="Black"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</DataTemplate.Resources>
<StackPanel >
<!--MouseLeftButtonDown="MenuItem_MouseLeftButtonDown"
MouseLeftButtonUp="UIElement_OnMouseLeftButtonUp"-->
<Grid Cursor="Hand" Name="Item" IsEnabled="{Binding IsEnabled}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="1"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<!--<RowDefinition Height="1"></RowDefinition>-->
</Grid.RowDefinitions>
<Grid.InputBindings>
<MouseBinding Command="{Binding ItemCommand}" MouseAction="LeftClick"/>
</Grid.InputBindings>
<TextBlock x:Name="TimeFrameItemText" VerticalAlignment="Center" Grid.Column="1" Grid.Row="1"
Foreground="{StaticResource PopupForegroundBrush}" Height="22" Text="{Binding TimeFrameLabel}"
Width="{Binding ElementName=popup, Path=DataContext.OptionTextWidth,Converter={StaticResource DummyConverter}}">
<TextBlock>
</Grid>
<Rectangle Width="Auto" Height="1" Visibility="{Binding IsLast,Converter={StaticResource BoolVisibilityConverter},ConverterParameter=Inverse}" Fill="{StaticResource PopupSeparatorBrush}"/>
</StackPanel>
<DataTemplate.Triggers>
<!--<Trigger SourceName="Item" Property="IsMouseOver" Value="True">
<Setter TargetName="Item" Property="Background" Value="#2097B5"/>
<Setter TargetName="TimeFrameItemText" Property="Foreground" Value="White"/>
</Trigger>-->
<EventTrigger RoutedEvent="UIElement.MouseEnter" SourceName="Item">
<BeginStoryboard x:Name="OnGrdMouseEnter_BeginStoryboard" Storyboard="{StaticResource OnGrdMouseEnter}"/>
</EventTrigger>
<EventTrigger RoutedEvent="UIElement.MouseLeave" SourceName="Item">
<BeginStoryboard x:Name="OnGrdMouseLeave_BeginStoryboard" Storyboard="{StaticResource OnGrdMouseLeave}"/>
</EventTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Border>
</Popup>
To make MouseEnter and MouseLeave event working for grid, set the background color of the grid to Transparent.
This question already has answers here:
Detect mouse directly over border in WPF
(2 answers)
Closed 8 years ago.
I build a small control with a panel of two buttons. When I hover the control I want to show the panel and hide it when I leave. Everything works great, but I have one bug. When I move the cursor from the TextBlock to the Image my Storyboard run again. I dont understand why because both of them are inside the control. I try to add a Border to wrap the control, but it didnt work.
<UserControl.Resources>
<Storyboard x:Key="Show">
<DoubleAnimationUsingKeyFrames
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)"
Storyboard.TargetName="QuickPanel">
<EasingDoubleKeyFrame KeyTime="0" Value="18"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="Hide">
<DoubleAnimationUsingKeyFrames
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)"
Storyboard.TargetName="QuickPanel">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="18"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</UserControl.Resources>
<UserControl.Triggers>
<EventTrigger RoutedEvent="Border.MouseEnter">
<BeginStoryboard Storyboard="{StaticResource Show}"/>
</EventTrigger>
<EventTrigger RoutedEvent="Border.MouseLeave">
<BeginStoryboard Storyboard="{StaticResource Hide}"/>
</EventTrigger>
</UserControl.Triggers>
<Border Width="144" Height="36" ClipToBounds="True" BorderThickness="0">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Image Source="http://www.streamplay.fr/thumb/fanart/3000/3000/1321396.jpg"
VerticalAlignment="Center" HorizontalAlignment="Center" Margin="2"
Stretch="UniformToFill" Height="34" Width="34"/>
<Grid Grid.Column="1">
<StackPanel VerticalAlignment="Center" Margin="6,0,0,0">
<TextBlock FontSize="12" FontWeight="DemiBold">Sample Title</TextBlock>
<TextBlock FontSize="10" Text="{Binding Title, Mode=TwoWay}"></TextBlock>
</StackPanel>
</Grid>
<StackPanel x:Name="QuickPanel" Grid.Column="1" Width="18" HorizontalAlignment="Right" RenderTransformOrigin="0.5,0.5">
<StackPanel.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform X="18"/>
</TransformGroup>
</StackPanel.RenderTransform>
<Button x:Name="button" Height="18" Content="p" IsDefault="True" />
<Button x:Name="button1" Height="18" Content="k" />
</StackPanel>
</Grid>
</Border>
Any idea how to change this ?
You need to set a background to your Border element UI:
Border Background="Transparent" ...
If you don't set the background, the space between image and textblock is your parent window.
I am trying to access a control from within a template using the Template.FindName("Name",templatedParent) function. For some reason it is returning null.
I am using the XamlReader to load the below xaml.
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication2;assembly=WpfApplication2"
xmlns:ice="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
xmlns:igecac="clr-namespace:namespace1;assembly=assembly1"
Loaded="Window_Loaded"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<Style TargetType="{x:Type igecac:ApplicationContainer}">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igecac:ApplicationContainer}">
<ControlTemplate.Resources>
<DataTemplate x:Key="selectedItemTemplate">
<TextBlock Padding="10,10,10,10" Text="{Binding Path=Id}" Background="{DynamicResource PanelBrush}" Width="100" Height="50">
<TextBlock.Foreground>
<SolidColorBrush Color="Black" ice:Freeze="True" />
</TextBlock.Foreground>
</TextBlock>
</DataTemplate>
<DataTemplate x:Key="ItemTemplate">
<TextBlock Padding="10,10,10,10" Text="{Binding Path=Id}" Background="{DynamicResource ObjectStrokeBrush}" Width="100" Height="50">
<TextBlock.Foreground>
<SolidColorBrush Color="Black" ice:Freeze="True" />
</TextBlock.Foreground>
</TextBlock>
</DataTemplate>
</ControlTemplate.Resources>
<Grid Background="{DynamicResource ObjectGradientBrush}">
<Grid.RowDefinitions />
<Grid.ColumnDefinitions>
<ColumnDefinition Name="grd1" Width="110" />
<ColumnDefinition Width="50" />
<ColumnDefinition Width="2*" />
</Grid.ColumnDefinitions>
<Canvas Margin="0,-7,0,0" Width="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=HostableWidth}" Height="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=HostableHeight}">
<ContentPresenter Name="PART_HostArea" Content="{Binding Path=SelectedPanel.Document.Editor}" />
</Canvas>
<igecac:CustomListBox Name="PART_AssociatedPanels" ItemsSource="{Binding Path=AssociatedPanels}" SelectedItem="{Binding Path=SelectedPanel, Mode=TwoWay}" IsSynchronizedWithCurrentItem="True" HorizontalContentAlignment="Stretch" Background="{DynamicResource ObjectGradientBrush}">
<igecac:CustomListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" IsItemsHost="True" />
</ItemsPanelTemplate>
</igecac:CustomListBox.ItemsPanel>
<igecac:CustomListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="ContentControl.ContentTemplate" Value="{StaticResource ItemTemplate}" />
<Setter Property="Control.HorizontalContentAlignment" Value="Stretch" />
<Setter Property="FrameworkElement.Margin" Value="1,1,1,1" />
<Setter Property="Control.Padding" Value="2,2,2,2" />
<Setter Property="UIElement.Visibility" Value="Visible" />
<Style.Triggers>
<Trigger Property="Selector.IsSelected" Value="True">
<Setter Property="ContentControl.ContentTemplate" Value="{StaticResource selectedItemTemplate}" />
</Trigger>
</Style.Triggers>
</Style>
</igecac:CustomListBox.ItemContainerStyle>
</igecac:CustomListBox>
<Grid Name="CloseButton" Margin="-6,-6,0,0" Grid.Column="1" Width="50" Height="40" HorizontalAlignment="Left" Visibility="Visible" VerticalAlignment="Top">
<Grid.RowDefinitions />
<Grid.ColumnDefinitions />
<Rectangle Fill="{DynamicResource ObjectStrokeBrush}" Width="40" Height="25" HorizontalAlignment="Center" VerticalAlignment="Center" />
<Label Content="Close" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
<Grid Name="OpenButton" Margin="-5,-6,0,0" Grid.Column="0" Width="50" Height="40" HorizontalAlignment="Left" Visibility="Hidden" VerticalAlignment="Top">
<Grid.RowDefinitions />
<Grid.ColumnDefinitions />
<Rectangle Fill="{DynamicResource ObjectStrokeBrush}" Width="40" Height="25" HorizontalAlignment="Center" VerticalAlignment="Center" />
<Label Content="Open" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
</Grid>
<ControlTemplate.Triggers>
<EventTrigger SourceName="CloseButton" RoutedEvent="Mouse.MouseDown">
<EventTrigger.Actions>
<BeginStoryboard>
<BeginStoryboard.Storyboard>
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_AssociatedPanels" Storyboard.TargetProperty="(UIElement.Visibility)">
<DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Hidden}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="OpenButton" Storyboard.TargetProperty="(UIElement.Visibility)">
<DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Visible}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="CloseButton" Storyboard.TargetProperty="(UIElement.Visibility)">
<DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Hidden}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard.Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<EventTrigger SourceName="OpenButton" RoutedEvent="Mouse.MouseDown">
<EventTrigger.Actions>
<BeginStoryboard>
<BeginStoryboard.Storyboard>
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_AssociatedPanels" Storyboard.TargetProperty="(UIElement.Visibility)">
<DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Visible}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="OpenButton" Storyboard.TargetProperty="(UIElement.Visibility)">
<DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Hidden}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="CloseButton" Storyboard.TargetProperty="(UIElement.Visibility)">
<DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Visible}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard.Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="igecac:ApplicationContainer.HostableWidth" Value="720" />
<Setter Property="igecac:ApplicationContainer.HostableHeight" Value="590" />
</Style>
</Window.Resources>
<Grid>
<igecac:ApplicationContainer x:Name="_ae51329a9692472099e1c0ed6b6b7937"
Tag="TemplatePart" Width="800" Height="600"
HostableWidth="500" HostableHeight="500">
</igecac:ApplicationContainer>
<igecac:DecimalKeypad/>
<igecac:HexKeypad/>
</Grid>
In the above xaml i have a custom control called ApplicationContainer. I have overridden the OnApplyTemplate() method in the code representing the class and i apply the above style to the control(haven't defined x:Key so it gets applied by default).
I see that on XamlReader.Load() the OnApplyTemplate() not called. That apart, if i try accessing the _ae51329a9692472099e1c0ed6b6b7937.Template i can see everything defined in the template(So, i feel the template is applied properly)
But when i do this.Template.FindName("PART_HostArea",this) in the control class OnApplyTemplate method(i call it explicitly) it returns me null.
Have you tried GetTemplateChild(ControlName)?
in my silverlight for windows phone app, i've created this xaml in the mainpage of a basic project :
<phone:PhoneApplicationPage.Resources>
<Style x:Key="TestStyle" TargetType="CheckBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="CheckBox">
<Grid x:Name="grid" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}">
<vsm:VisualStateManager.VisualStateGroups>
<vsm:VisualStateGroup x:Name="CheckStates">
<vsm:VisualState x:Name="Checked">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="image" Storyboard.TargetProperty="Source">
<DiscreteObjectKeyFrame KeyTime="0" Value="ApplicationIcon.png"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</vsm:VisualState>
<vsm:VisualState x:Name="Unchecked"/>
<vsm:VisualState x:Name="Indeterminate">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="image" Storyboard.TargetProperty="Source">
<DiscreteObjectKeyFrame KeyTime="0" Value="ApplicationIcon.png"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</vsm:VisualState>
</vsm:VisualStateGroup>
</vsm:VisualStateManager.VisualStateGroups>
<Image x:Name="image" Source="ApplicationIcon.png" Margin="0 0 0 10" Stretch="Fill" VerticalAlignment="Center" Width="32" Height="32"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</phone:PhoneApplicationPage.Resources>
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<CheckBox Style="{StaticResource TestStyle}" />
</Grid>
</Grid>
When running the application, the image is correctly displayed in the application, but not in the designer.
This is annoying because I can't style my application.
Any way to fix that ? workaround ?
Thanks in advance for any help
Should be a bug, in blend it's ok
I'm trying to display a list of bound data in a then get a Canvas to animate behind each row. I'm having trouble getting a Storyboard to Begin when I place it inside a template. Here is an example of the XAML I have so far:
<ListBox x:Name="MyListBox" Background="Transparent" Foreground="White" Height="200" Width="400" BorderThickness="0" Margin="0">
<ListBox.ItemTemplate>
<DataTemplate x:Name="MySingleDataTemplate">
<StackPanel Orientation="Horizontal" x:Name="MySingleStackPanel" Margin="0">
<StackPanel.Resources>
<Storyboard x:Name="MySingleStoryboard" BeginTime="0:0:1">
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="Canvas99" Storyboard.TargetProperty="Width"
AutoReverse="True" RepeatBehavior="Forever">
<LinearDoubleKeyFrame Value="0" KeyTime="0:0:0" />
<LinearDoubleKeyFrame Value="400" KeyTime="0:0:3" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</StackPanel.Resources>
<Grid Background="Black" x:Name="MySingleGrid" Margin="0" ShowGridLines="False">
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="Col0" Width="300" />
<ColumnDefinition x:Name="Col1" Width="100" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="30" x:Name="Row0" />
</Grid.RowDefinitions>
<Canvas Background="{Binding CanvasColour}" Grid.Row="0" Grid.Column="0" x:Name="Canvas99" HorizontalAlignment="Left" />
<TextBlock Grid.Column="0" Grid.Row="0" Text="{Binding Field1}" Margin="0"/>
<TextBlock Grid.Column="1" Grid.Row="0" Text="{Binding Field2}" Margin="0"/>
</Grid>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
How can I call the equivalent of the C#:
MySingleStoryboard.Begin();
Is there a way I can get it to start from C# or are there some other properties or Triggers I can use in Silverlight? Or am I going about it in completely the wrong way?
thankyou
Mike
Managed to answer my own question! I need to add to my StackPanel, like this:
<StackPanel.Triggers>
<EventTrigger RoutedEvent="StackPanel.Loaded">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard x:Name="MySingleStoryboard" BeginTime="0:0:1">
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="Canvas99" Storyboard.TargetProperty="Width"
AutoReverse="True" RepeatBehavior="Forever">
<LinearDoubleKeyFrame Value="0" KeyTime="0:0:0" />
<LinearDoubleKeyFrame Value="400" KeyTime="0:0:3" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</StackPanel.Triggers>
Works a treat, now I just need to get rid of all the margins/boarders etc on the listbox and I'll be happy.... for now.
Mike