F
F
Festelo2016-12-04 20:15:06
WPF
Festelo, 2016-12-04 20:15:06

Why doesn't the Margin of the button change?

There is a code:

Button btn = (Button)sender;
btn.Margin = new Thickness();
Thickness margin = btn.Margin;
ThicknessAnimation anim = new ThicknessAnimation();  
...

It is logical that the margin variable should be equal to {0,0,0,0}, but it is not! The Margin value of the btn button does not change, it remains equal to the previous value. Why is that?
ZFxlqxb.pngbStr2E9.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Nemiro, 2016-12-04
@Festelo

Probably something like ThicknessAnimation is changing the Margin of the button.
You need to remove the animation before making changes:

Button btn = (Button)sender;

button.BeginAnimation(MarginProperty, null);

btn.Margin = new Thickness();
Thickness margin = btn.Margin;
// ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question