Shaharyar
Shaharyar

Reputation: 12459

Label animation

I am trying to animate a Label in WPF. On a timer tick. I am doing it like this:

SlideLabel.Margin.Left = 90;

But there is an exception:

Cannot modify the return value of 'System.Windows.FrameworkElement.Margin' because it is not a variable

I got the answer here: Setting Margin Properties in code

But I am little bit confuse about one thing, probably because of weak OOP concepts. If I create a new instance of Thickness every time like this:

SildeLabel.Margin = new Thickness(90, 18, -1, 0);

So these all the instances will be in memory and are referenced. So the GC will not dispose them. It will take a lot of memory. Am I correct here?

Actually I want to make a slide at the bottom of the screen like news channels have. So I couldn't find any better to make this. If this is worst, then kindly tell me about any other way to accomplish this.

Upvotes: 0

Views: 1195

Answers (1)

Nitesh
Nitesh

Reputation: 7429

I would suggest to use TranslateTransform with StoryBoard to achieve your desired animation.

Please check this MSDN code example.

Hope it helps.

Upvotes: 1

Related Questions