Click here to Skip to main content
15,894,324 members
Home / Discussions / WPF
   

WPF

 
QuestionWPF TabContol problem Pin
Jacobus0116-Jun-09 22:36
Jacobus0116-Jun-09 22:36 
AnswerRe: WPF TabContol problem Pin
ABitSmart17-Jun-09 2:57
ABitSmart17-Jun-09 2:57 
AnswerRe: WPF TabContol problem Pin
#realJSOP17-Jun-09 5:37
mve#realJSOP17-Jun-09 5:37 
GeneralRe: WPF TabContol problem Pin
Jacobus0117-Jun-09 20:38
Jacobus0117-Jun-09 20:38 
GeneralRe: WPF TabContol problem Pin
#realJSOP17-Jun-09 23:13
mve#realJSOP17-Jun-09 23:13 
Questionhow to use the same file in two project in visual studio Pin
bigkingjiang16-Jun-09 21:43
bigkingjiang16-Jun-09 21:43 
AnswerRe: how to use the same file in two project in visual studio - Link it Pin
ProtoBytes19-Jun-09 3:50
ProtoBytes19-Jun-09 3:50 
QuestionFrozen Property After Animating [SOLVED] Pin
#realJSOP15-Jun-09 9:26
mve#realJSOP15-Jun-09 9:26 
SOLUTION:

I had to do this in the Completed event handler:

//--------------------------------------------------------------------------------
void CollapseAnimator_Completed(object sender, EventArgs e)
{
    GenericAnimationEnd(false);
}

//--------------------------------------------------------------------------------
void ExpandAnimator_Completed(object sender, EventArgs e)
{
    GenericAnimationEnd(true);
}

//--------------------------------------------------------------------------------
private void GenericAnimationEnd( bool expanding)
{
    double height = this.expandingGrid.ActualHeight;
    this.CollapseAnimator.FillBehavior = FillBehavior.Stop;
    this.ExpandAnimator.FillBehavior = FillBehavior.Stop;
    this.expandingGrid.Height = height;
}


------------------------------------------

Last week, I posted a message about how a property is being frozen after animating a control. I have since moved the relevant code to a sample application. If anyone feels like looking at it. I would love to know what I'm doing wrong.

WIDTH ALERT - I didn't bother reformatting it, so the posted code might be wider than your screen. Simply create a new WPF application called "AnimateSample" and replace the contents of the appropriate files with the code below.

Here's Window1.XAML:
<Window x:Class="AnimateSample.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Width="800" Height="600">
    
    <Window.Resources>
        <Storyboard x:Key="AnimateGridExpand">
            <DoubleAnimation To="300" Duration="0:0:0.2" Storyboard.TargetName="expandingGrid" Storyboard.TargetProperty="Height" />
        </Storyboard>
        <Storyboard x:Key="AnimateGridCollapse">
            <DoubleAnimation To="100" Duration="0:0:0.2" Storyboard.TargetName="expandingGrid" Storyboard.TargetProperty="Height" />
        </Storyboard>

    </Window.Resources>

    <Grid>
        <Button Name="buttonGrowWithAnimation" Width="150" Height="23" Margin="20,5,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Click="buttonGrowWithAnimation_Click">Grow With Animation</Button>
        <Button Name="buttonGrowWithoutAnimation" Width="150" Height="23" Margin="0,5,20,0" HorizontalAlignment="Right" VerticalAlignment="Top" Click="buttonGrowWithoutAnimation_Click">Grow Without Animation</Button>
        <Grid Name="expandingGrid" Margin="0,34,0,0" Height="100" VerticalAlignment="Top">
            <Border Name="border1" BorderThickness="2" CornerRadius="6,6,6,6" Background="LightSlateGray" BorderBrush="Black">
                <CheckBox Height="16" Name="checkBox1" Width="120">CheckBox</CheckBox>
            </Border>
        </Grid>
    </Grid>
    
</Window>


And here's Window1.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using System.Diagnostics;
using System.Windows.Media.Animation;

namespace AnimateSample
{
	/// <summary>
	/// Interaction logic for Window1.xaml
	/// </summary>
	public partial class Window1 : Window
	{
		public Storyboard   ExpandAnimator    { get; set; }
		public Storyboard   CollapseAnimator  { get; set; }
		public bool         Expanded          { get; set; }
		public int          OriginalZIndex    { get; set; }
		public double       HeightChangeValue { get; set; }


		//--------------------------------------------------------------------------------
		/// <summary>
		/// Costructor
		/// </summary>
		public Window1()
		{
			InitializeComponent();

			// we start out in collapsed mode
			this.Expanded = false;

			// In order to add an event handler (or change other properties), we have to 
			// get an "unfrozen" copy of the storyboard. We have to use the Clone method 
			// to accomplish this.
			this.ExpandAnimator   = ((Storyboard)TryFindResource("AnimateGridExpand")).Clone();
			this.CollapseAnimator = ((Storyboard)TryFindResource("AnimateGridCollapse")).Clone();

			// Retrieve the To value from both storyboards so we can calculate the height 
			// change we will need to make in "manual" (non-animated) mode.
			DoubleAnimation daExpand   = (DoubleAnimation)ExpandAnimator.Children[0];
			DoubleAnimation daCollapse = (DoubleAnimation)CollapseAnimator.Children[0];

			// Here's our manual height change value
			this.HeightChangeValue = (double)daExpand.To - (double)daCollapse.To;

			Debug.WriteLine("\n---------------------------------------------------------------------------------");
			Debug.WriteLine("Application Starts");
			Debug.WriteLine("---------------------------------------------------------------------------------");
			Debug.WriteLine(string.Format("HeightChangeValue = {0:0.0}", this.HeightChangeValue));
		}


		//--------------------------------------------------------------------------------
		/// <summary>
		/// Fired when the user clicks the "Grow With Animation" button
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void buttonGrowWithAnimation_Click(object sender, RoutedEventArgs e)
		{
			Debug.WriteLine("----");
			Debug.WriteLine((this.Expanded)?"Expanded" : "Collapsed");

			// set our animation target
			Debug.WriteLine("Setting animation target to the grid");
			Storyboard.SetTarget(this.ExpandAnimator, this.expandingGrid);
			Storyboard.SetTarget(this.CollapseAnimator, this.expandingGrid);

			// expand or collapse, depending on the current state
			if (this.Expanded)
			{
				Debug.WriteLine("Collapsing with animation");
				this.CollapseAnimator.Begin(this);
			}
			else
			{
				Debug.WriteLine("Expanding with animation");
				this.ExpandAnimator.Begin(this);
			}

			// set our current state to the opposite of what it was
			this.Expanded = !this.Expanded;
			Debug.WriteLine((this.Expanded)?"Expanded" : "Collapsed");
		}


		//--------------------------------------------------------------------------------
		/// <summary>
		/// Fired when the user clicks the "Grow Without Animation" button
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void buttonGrowWithoutAnimation_Click(object sender, RoutedEventArgs e)
		{
			Debug.WriteLine("----");
			Debug.WriteLine((this.Expanded)?"Expanded" : "Collapsed");

			// set our animation targets to null
			Debug.WriteLine("Setting animation target to null");
			Storyboard.SetTarget(this.ExpandAnimator, null);
			Storyboard.SetTarget(this.CollapseAnimator, null);

			// expand or collapse, depending on the current state
			if (this.Expanded)
			{
				Debug.WriteLine("Collapsing WITHOUT animation");
				// Because of the problem I'm having, I have to make sure 
				// the value I'm setting passes a sanity check
				this.expandingGrid.Height = Math.Max(100d, this.expandingGrid.ActualHeight - this.HeightChangeValue);
			}
			else
			{
				Debug.WriteLine("Collapsing WITHOUT animation");
				this.expandingGrid.Height = this.expandingGrid.ActualHeight + this.HeightChangeValue;
			}

			// set our current state to the opposite of what it was
			this.Expanded = !this.Expanded;
			Debug.WriteLine((this.Expanded)?"Expanded" : "Collapsed");
		}
	}
}



"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001


modified on Monday, June 15, 2009 5:03 PM

QuestionUpdate Databindings to Object on assignment to new Object Pin
Dan Payment15-Jun-09 7:59
Dan Payment15-Jun-09 7:59 
AnswerRe: Update Databindings to Object on assignment to new Object Pin
Mark Salsbery15-Jun-09 8:17
Mark Salsbery15-Jun-09 8:17 
GeneralRe: Update Databindings to Object on assignment to new Object Pin
Dan Payment15-Jun-09 9:44
Dan Payment15-Jun-09 9:44 
Questionfence-sitting : SilverLight vs. WPF : one year out ... ? Pin
BillWoodruff15-Jun-09 7:47
professionalBillWoodruff15-Jun-09 7:47 
AnswerRe: fence-sitting : SilverLight vs. WPF : one year out ... ? Pin
Mark Salsbery15-Jun-09 8:13
Mark Salsbery15-Jun-09 8:13 
GeneralRe: fence-sitting : SilverLight vs. WPF : one year out ... ? Pin
BillWoodruff15-Jun-09 9:17
professionalBillWoodruff15-Jun-09 9:17 
QuestionWPF listbox scroolbar width Pin
peterotoole15-Jun-09 4:52
peterotoole15-Jun-09 4:52 
AnswerRe: WPF listbox scroolbar width Pin
Pete O'Hanlon15-Jun-09 5:01
mvePete O'Hanlon15-Jun-09 5:01 
GeneralRe: WPF listbox scroolbar width Pin
#realJSOP17-Jun-09 5:41
mve#realJSOP17-Jun-09 5:41 
QuestionConsume huge excel sheets by WCF Services Pin
Vipul Mehta15-Jun-09 4:26
Vipul Mehta15-Jun-09 4:26 
AnswerRe: Consume huge excel sheets by WCF Services Pin
RugbyLeague15-Jun-09 10:22
RugbyLeague15-Jun-09 10:22 
QuestionGray focus comes on treeview Pin
Ravi Mori15-Jun-09 3:02
Ravi Mori15-Jun-09 3:02 
AnswerRe: Gray focus comes on treeview Pin
ABitSmart15-Jun-09 3:35
ABitSmart15-Jun-09 3:35 
GeneralRe: Gray focus comes on treeview Pin
Ravi Mori15-Jun-09 3:52
Ravi Mori15-Jun-09 3:52 
GeneralRe: Gray focus comes on treeview Pin
ABitSmart15-Jun-09 4:07
ABitSmart15-Jun-09 4:07 
QuestionCapture mouse event on slider track [modified] Pin
Christian Graus15-Jun-09 0:19
protectorChristian Graus15-Jun-09 0:19 
AnswerRe: Capture mouse event on slider track Pin
Pete O'Hanlon15-Jun-09 0:21
mvePete O'Hanlon15-Jun-09 0:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.