Begin Storyboard Animation from codebehind

Posted on: Tue Aug 04 15:18:21 -0700 2009. Updated on: Tue Aug 04 15:20:29 -0700 2009.
Category: WPF

Animations with storyboards in WPF are cool, but often we need to be able to trigger them to start from cs codebehind. For example, on a button click. Here the animationKey param is the key that is defined in the xaml for your storyboard.

private void StartAnimation(string animationKey)
{
     Storyboard pageViewAnimation = (Storyboard)FindResource(animationKey);
     pageViewAnimation.Begin();
}

Set Image Source in WPF

Posted on: Tue Aug 04 12:32:32 -0700 2009. Updated on: Thu Aug 06 11:04:16 -0700 2009.
Category: WPF

Setting the Image.Source property in WPF. Note this is slightly different than in silverlight because it requires an object holding the image data as source.


private void SetPageViewImage(string sourceFile)
{
	Uri uri = new Uri(sourceFile, UriKind.Relative);
	ImageSource imgSource = new BitmapImage(uri);
	PageViewImage.Source = imgSource;
	PageViewImage.Visibility = Visibility.Visible; //optional
}

Ads

Categories

About

Random foliage

This website is meant to be a reference for ASP Dot Net developers. The entries are a compilation of things I've figured out how to do and that I deem useful to keep of track for future reference. Assumptions: web development with: C Sharp (vb sucks), visual studio 05/08, .net 3.5, meant for programmers. Written by: James Reategui.