|
-
Jan 29th, 2010, 06:46 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Sliding objects with code
I am having a slight problem sliding controls on a form with C# code. So far I found this article http://vbcity.com/blogs/xtab/archive...on-in-wpf.aspx on how to do it with XAML, but I need to do it with C# because items will only slide to places depending on what item is selected in a textbox.
I have my controls setup like this:

On the left is how it should look with item one selected, and on the right is how it should look with item 2 selected. With the textbox gone the height of the form will also reduce as well and when it comes back (item 1) it will increase.
The code I tried so far is this, but it doesn't seem to work so I must be doing something wrong but don't know what as I am fairly new to WPF.
Code:
Storyboard storyboard = new Storyboard();
TimeSpan duration = new TimeSpan(0, 0, 3);
DoubleAnimation animation = new DoubleAnimation();
//animation.From = 0.0;
//animation.To = 1.0;
animation.By = 100;
animation.Duration = new Duration(duration);
Storyboard.SetTargetName(animation, btnTest.Name);
Storyboard.SetTargetProperty(animation, new PropertyPath(TranslateTransform.XProperty));
storyboard.Children.Add(animation);
storyboard.Begin(this);
-
Jan 30th, 2010, 05:15 PM
#2
Re: Sliding objects with code
If you are not bothered about animating it and simply want the controls below (ie the button) to move up when the textbox is made invisible then you can simply set the textbox's Visibility property to Collapsed rather than Hidden.
However, I'll assume you do want to animate it, so here's an example of how I would do it (this is to slide the button up to just beneath the combobox) :
Code:
Textbox1.Visibility = Windows.Visibility.Hidden
Dim Anim As New Animation.ThicknessAnimation
Anim.To = New Thickness(0, -15, 0, 0)
Anim.Duration = New Duration(TimeSpan.FromSeconds(1))
Button1.BeginAnimation(FrameworkElement.MarginProperty, Anim)
and here's a complete example:
Code:
Class Window1
Private Sub ComboBox1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.SelectionChangedEventArgs) Handles ComboBox1.SelectionChanged
If ComboBox1.SelectedIndex = 0 Then
SlideDown()
ElseIf ComboBox1.SelectedIndex = 1 Then
SlideUp()
End If
End Sub
Private Sub SlideUp()
Textbox1.Visibility = Windows.Visibility.Hidden
Dim Anim As New Animation.ThicknessAnimation
Anim.To = New Thickness(0, -15, 0, 0)
Anim.Duration = New Duration(TimeSpan.FromSeconds(1))
Button1.BeginAnimation(FrameworkElement.MarginProperty, Anim)
End Sub
Private Sub SlideDown()
Dim Anim As New Animation.ThicknessAnimation
Anim.To = New Thickness(0, 0, 0, 0)
Anim.Duration = New Duration(TimeSpan.FromSeconds(1))
Button1.BeginAnimation(FrameworkElement.MarginProperty, Anim)
Textbox1.Visibility = Windows.Visibility.Visible
End Sub
End Class
-
Feb 1st, 2010, 12:44 PM
#3
Thread Starter
Addicted Member
Re: Sliding objects with code
Wow thanks Chris!!
-
Feb 1st, 2010, 01:27 PM
#4
Re: [RESOLVED] Sliding objects with code
No problem
-
Feb 1st, 2010, 02:42 PM
#5
Thread Starter
Addicted Member
Re: [RESOLVED] Sliding objects with code
Won't let me add rep to you, says I need to share it around more before giving you more lol
-
Feb 1st, 2010, 02:45 PM
#6
Re: [RESOLVED] Sliding objects with code
lol thats ok, its the thought that counts
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|