Skip to main content

Microsoft Silverlight

Unanswered Question actual height and animationRSS Feed

(0)

lumpenprole
lumpenprole

Member

Member

1 points

8 Posts

actual height and animation

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.Lutay
Sergey.L...

Contributor

Contributor

7128 points

1,340 Posts

Re: actual height and animation

Hi,

When your shape is growing, it is changing the scale transform property of shape. You should check that property.

(If this has answered your question, please click on "mark as answer" on this post. Thank you!)

Blog

Twitter

Sincerely,
Sergey Lutay

lumpenprole
lumpenprole

Member

Member

1 points

8 Posts

Re: Re: actual height and animation

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?

Sergey.Lutay
Sergey.L...

Contributor

Contributor

7128 points

1,340 Posts

Re: Re: actual height and animation

Which is the base type of your custom object?

(If this has answered your question, please click on "mark as answer" on this post. Thank you!)

Blog

Twitter

Sincerely,
Sergey Lutay

lumpenprole
lumpenprole

Member

Member

1 points

8 Posts

Re: Re: Re: actual height and animation

it's a custom class extended from Canvas.

Sergey.Lutay
Sergey.L...

Contributor

Contributor

7128 points

1,340 Posts

Re: Re: Re: actual height and animation

If you have inherited the custom class from Canvas class you should try to use RenderSize property.
 

(If this has answered your question, please click on "mark as answer" on this post. Thank you!)

Blog

Twitter

Sincerely,
Sergey Lutay

lumpenprole
lumpenprole

Member

Member

1 points

8 Posts

Re: Re: Re: Re: actual height and animation

nope, RenderSize holds on the original size as well.

Yi-Lun Luo - MSFT
Yi-Lun L...

All-Star

All-Star

25052 points

2,747 Posts

Re: actual height and animation

Hello, normally this should work. But your situation seems to be a little complex. Can you post some code or share a sample project?

shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.

lumpenprole
lumpenprole

Member

Member

1 points

8 Posts

Re: Re: actual height and animation

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.

lumpenprole
lumpenprole

Member

Member

1 points

8 Posts

Re: Re: Re: actual height and animation

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>


Here's the C#:


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));
}
}
}


Here's the XAML for the page:


<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>


And here's the C#:


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);
}
}
}



The odd thing here is that this reports zero in every case. I'm thinking text block has some issues with ActualHeight, which is frustrating because it's made to dynamically add text, so you're going to need to get the size of things after you change them.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities