Reputation: 5414
I have a large WPF application. I'm looking to make the UI multithreaded. As part of that process, I'm moving some application-level control and style resources to the Window level. (I know from experience that I can't use DynamicResource and resolve at the application level unless I'm on the application thread.) Anyway, I moved a bunch of control resources. The application works find with one nasty problem: all of my animations on FrameworkElement Height and Width broke. They all fail because the control is of width or height NaN. These animations all work when the control templates are registered at the application level. All of my controls where I animate height or width have appropriate default height or width values that are not NaN. Why would the resource location affect this?
Upvotes: 1
Views: 743
Reputation: 726
This is late, but in case someone else get into this. the DoubleAnimation is a helper class that allows for a double to go from a value to another in a smooth fashion. As you don't specify a Width explicitly for your grid, the default value is NaN. Thus the DoubleAnimation is trying to go from NaN to Whatever the target value. This cannot be done for obvious reasons. If you set the Width of the grid, it should work properly.
A workaround would be to set the grid width after it loads in the constructor :
public Grid()
{
InitializeComponent();
this.Loaded += (s, _) => this.Width = this.ActualWidth;
}
Hope this help.
Upvotes: 0
Reputation: 1193
Use ActualWidth and ActualHeight. Nan means that these propeties are not set yet. https://stackoverflow.com/a/607849/3955716
Upvotes: 1