Hi there!
I’m currently learning WPF / MVVM and I’m trying to do the following:


– I have a view and a corresponding ViewModel.
– This ViewModel has a List<int> with a set of values.
– I want to animate a rectangle once, by changing it’s width to each value of the List in the List’s order.
What I’ve tried:
– I’ve tried to Bind the Width: width=”{Binding widthA01}”
– In the viewmodel, I iterated through the list, attributing widthA01 with a Thread.Sleep() in between.
The result is that I don’t see anything (width 0) while the loop is running, then in the end the rectangle gets the width of the last value in the list.
I’ve looked into XAML animations, but I only found about From=”” … To=””, but that’s not what I want. I want to go through all the values in that list (45, 68, 123, 12, etc).
Thanks in advance!
EDIT: I’m trying to do this without Codebehind.


https://docs.microsoft.com/en-us/dotnet/desktop/wpf/graphics-multimedia/how-to-animate-a-double-by-using-key-frames
You’ll still need some code to convert the int values into keyframes. The “proper” way would probably be writing a converter.
C# devs
null reference exceptions

source