Skip to main content
Home Forums Silverlight Programming Programming with .NET - General actual height and animation
9 replies. Latest Post by lumpenprole on October 23, 2008.
(0)
lumpenprole
Member
1 points
8 Posts
10-17-2008 12:20 PM |
So, I have some elements moving around in a custom object via CompositionTarget.Rendering (which is the best addition ever, btw) and I'm having some problems getting the ActualHeight. ActualHeight seems to stay static even if the rendered object grows by dint of objects within it changing position. I was under the impression, and the docs don't dissuade me, that ActualHeight is updated on render. Is that wrong?
Sergey.L...
Contributor
7128 points
1,340 Posts
10-17-2008 2:03 PM |
Hi,
When your shape is growing, it is changing the scale transform property of shape. You should check that property.
10-17-2008 2:34 PM |
well, it's not a shape, it's a custom object that's a canvas in xaml. it's not showing me scale properties, so I'm assuming it didn't inherit them. Am I wrong?
10-17-2008 2:40 PM |
Which is the base type of your custom object?
10-17-2008 2:45 PM |
it's a custom class extended from Canvas.
10-17-2008 3:08 PM |
10-17-2008 3:12 PM |
nope, RenderSize holds on the original size as well.
Yi-Lun L...
All-Star
25052 points
2,747 Posts
10-21-2008 7:16 AM |
Hello, normally this should work. But your situation seems to be a little complex. Can you post some code or share a sample project?
10-21-2008 1:20 PM |
I'll try to put an example together in the next couple days. As you said, it's complex, and I have a lot of other work to do.
10-23-2008 1:08 PM |
Okay, here we go: Here's the xaml of a custom text holder object:
<UserControl x:Class="Dynamic_Height_Test.text_item" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="50" Height="50"> <Canvas x:Name="LayoutRoot"> <TextBlock x:Name="text_holder" FontFamily="../Arial/arial.ttf#Arial" Width="100" Height="20" TextWrapping="Wrap" FontSize="12" Foreground="DarkOrange" Text="Test text" HorizontalAlignment="Left" /> <TextBlock x:Name="bottom_text" FontFamily="../Arial/arial.ttf#Arial" Width="100" Height="20" TextWrapping="Wrap" FontSize="12" Foreground="DarkOrange" Text="bottom text" HorizontalAlignment="Left" /> </Canvas > </UserControl>
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 Dynamic_Height_Test { public partial class text_item : UserControl { public string textSrc { get { return this.text_holder.Text; } set { this.text_holder.Text = value; setupText(); } } public text_item() { InitializeComponent(); } public void setupText() { //This works fine Canvas.SetTop(this.bottom_text, (this.text_holder.ActualHeight + Canvas.GetTop(this.text_holder) + 15)); } } }
<UserControl x:Class="Dynamic_Height_Test.Page" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:nsRoot="clr-namespace:Dynamic_Height_Test" Width="400" Height="300"> <Canvas x:Name="LayoutRoot" Background="CornflowerBlue"> <nsRoot:text_item x:Name="tester" Canvas.Left="15" Canvas.Top="15" textSrc="The absence of that dazed jury was a brief one. The verdict found the three prisoners guilty. Peter Blood looked round the scarlet-hung court. For an instant that foam of white faces seemed to heave before him."/> </Canvas > </UserControl>
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; using System.Diagnostics; namespace Dynamic_Height_Test { public partial class Page : UserControl { public Page() { InitializeComponent(); Debug.WriteLine("before: " + this.tester.ActualHeight); this.changeText(); Debug.WriteLine("after: " + this.tester.ActualHeight); } public void changeText() { this.tester.textSrc = "On a cane day-bed that had been set for him on the quarter-deck, sheltered from the dazzling, blistering sunshine by an improvised awning of brown sailcloth, lounged Peter Blood, a calf-bound, well-thumbed copy of Horace's Odes neglected in his hands."; Canvas.SetTop(this.tester.bottom_text, (this.tester.text_holder.ActualHeight + Canvas.GetTop(this.tester.text_holder) + 15)); Debug.WriteLine("in function: " + this.tester.ActualHeight); } } }