0

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.

Community
  • 1
  • 1
Shaharyar
  • 12,254
  • 4
  • 46
  • 66

1 Answers1

1

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

Please check this MSDN code example.

Hope it helps.

Nitesh
  • 7,261
  • 3
  • 30
  • 25