DoubleAnimation Crashes XAMLPad (MayCTP): Some Answers To Questions

I posted around some news groups to find an answer about my crash and a I recieved the following reply from Mike Hillbert.

When you're animating Width or Height, you have to specify both the From and the To, or you have to have specified the base value somewhere (e.g. on the element itself).

That's because when you don't specify the From or To it gets inferred from the base (unanimated) value. And in the case of Width and Height, the base value often isn't known until later when layout runs.

For example, in this page

<Page ...> ... <Page.Storyboards> <SetterTimeline TargetName="btn" Path="(Button.Width)" > <DoubleAnimation From="50" /> </SetterTimeline> </Page.Storyboards> ... <Button Width="100" Name="btn" Background="Blue">Click</Button> ...</Page>

the button's width is explicitly set on the <Button>, so the animation implicitly takes the width to 100 (from 50). But if you don't have the Width set in the <Button>, and don't have it anywhere else (e.g. in a Style), you have to have the From on the DoubleAnimation.

I think it basically sums up the problem quite simply. I wasn't giving the actual MenuItem a width, the "Owner Draw" elements in the Visual Tree had a width but the actual menu item didn't. Funnily enough (Well it is not that funny), I tried the suggested fixes and the crash was still occuring. I also tried the following bit of XAML which is supposed to give every control that meets the style criteria a width of 200:

<Style TargetType="{x:Type MenuItem}" x:Key="{x:Type MenuItem}" > <Setter Property="Width" Value="200" /> ... ...

I think my next course of action is to try and get this in a proper WinFX application rather than just XAMLPad.

About Me: Paul Kinlan

I lead the Chrome Developer Relations team at Google.

We want people to have the best experience possible on the web without having to install a native app or produce content in a walled garden.

Our team tries to make it easier for developers to build on the web by supporting every Chrome release, creating great content to support developers on web.dev, contributing to MDN, helping to improve browser compatibility, and some of the best developer tools like Lighthouse, Workbox, Squoosh to name just a few.