rhansen

I am struggling to figure out which dependency properties that can be used in .BeginAnimation in VB

There seems to be a real difference between C# and VB in this respect. See http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1152919&SiteID=1

Not sure why VB is different and there does not seem to be any list of .BeginAnimation dependacy properties I can use. The documentation is extremely C# biased and of near no help. :-(

Like why does C# use Image.LeftProperty (most logical I would say) and VB uses Canvas.LeftProperty. What does the canvas have to do with it and why does the documentation not mention anything about the C# Image.LeftProperty. According to the documentation Image does NOT have a LeftProperty property.

And no I don't really care about XAML right now. Only how to do it through code.



Re: Windows Presentation Foundation (WPF) What is it in VB

Wolf Schmidt - MSFT

There just plain isn't an Image.Left dependency property (in VB or otherwise). I think you were getting shortcutted code samples from people. Even in that other thread, there was a correction that they really meant Canvas.Left.

As far as BeginAnimation and what dependency properties you can use, the answer is, any dependency property can be used, but the instance needs to be animatable. Because the animation is targeted, you want to look at the target's type. And you want to look at the properties, not the fields. Because of how fields act in CLR, only the fields directly defined by the type show up in the members table, so you'd be missing all the inherited DPs if you just looked at fields.

For this and other reasons, the SDK doesn't document the DP behavior of a DP on the field pages. Instead, look at the property pages, because there's a very consistent convention that anything that's a (non-attached) dependency property should be exposed by a CLR property that will ease access in code as well as show up in members tables. Because many users are frequently referencing a DP without even knowing it (like you don't and can't care that someone backed their public property with a private field as opposed to some other means) we use the property pages to describe both the DP and regular CLR aspects of using that property. Once you're on a property page and you need the DP identifier field like you need for BeginAnimation, look down the page for a Dependency Property Information section, that'll name the field you need and what class it's on (and link you there in the docs too, although you'll soon see that looking at the field pages in the SDK won't be worth the effort).





Re: Windows Presentation Foundation (WPF) What is it in VB

rhansen

Wolf,

I sort of understand what you are writing but I still struggle with how to get from an image control to the 'Dependency Property Information' section you mention.

Questions:
1. Would you mind describing the whole path you would take from looking at an image control on a window to finding out which DPs can be used. Screen grap would be wonderful.

2. You write "Once you're on a property page and you need the DP identifier field like you need for BeginAnimation, look down the page for a Dependency Property Information section" What property page do you mean . My understanding of a property page is either the one you get to pressing F4 or right clicking an object(control) and selecting 'Properties' for a developer created property page . If I am correct then the VS2005 properties page is not grouped for WPF like it is for non WPF.

Suggestions:
1. Please be a bit less technical when you write documentation. Your doc's are starting to resemble the old IBM mainframe documentation from the 70' and 80' where you more or less had to be the person developing the system to be able to fully understand what was written. And believe me you don't want to go there.

2. Can we have more VB examples. I know C# is all very hip and so forth but just remember there is a huge VB developer base out there.

System:
Windows XP SP2
.NET 3 SDK
Visual Studio 2005 with .NET 3 extensions
Main language pure .NET Visual Basic i.e. no VB reference libs

rune





Re: Windows Presentation Foundation (WPF) What is it in VB

Wolf Schmidt - MSFT

1) There's two ways to get a list of possible properties on a type: the tools way and the SDK way. Because there are a lot of possible tools, I'm just going to describe the SDK way.

a) Figure out what type it is that you want to find the DPs for. If you're just setting properties on an instance, that's the type where you either called the ctor in code or where you declared the instance in object element syntax in XAML. If you're animating values, the type you want DPs for will be the target type of the animation. For your example here, that class is Image, so you will end up on the page: Image Class.

b) Scroll down to the bottom in the Related Topics area and get to the members table for Image: Image Members. If you have the MSDN TOC up, or are using the offline, the link from class to its members table is potentially easier than that. Also F1 for a class in some tools will take you to the members table direct, rather than the class page.

c) On the Image Members page, Collapse All, then expand only the Public Properties listing so that you get a more reasonable view.

d) Now look at what's left. If a property is backed by a dependency property, there will be a sentence in the summary that says "This is a dependency property." If the property is read-write, such that you can set it either as a local or as an animation, the summary description will always start with "Gets or sets ...". If the property is readonly, the summary description will start "Gets ... " (no "or sets").

2) I don't mean the VS2005 Property View. I mean the documentation page that documents the property on MSDN or in the offline collection. I can't speak to what level of designer support is available. In my own install of VS2005, the Property View doesn't seem to be working for WPF types.

So, to continue, once you've used the members table listings to scan descriptions for what you've determined is an interesting property to set, you click on a property name. I'll use Width for this example. On that page, scroll down until you see the Dependency Property Information table. The Identifier Field will list the name of the static field that you use for operations that require the DP ID field itself - things like SetValue, overriding metadata, animations in code, etc.

You don't necessarily need to go through all this each time, because there's a strict naming convention between DP wrapper properties and the DP ID fields that back them. Want to animate the Button.Width property Just reference Button.WidthProperty in the code. It's always the name of the property plus "Property". If you look at members tables though, you won't see WidthProperty as a field member of Button. That's just an artifact of how Microsoft documentation shows static fields; it only shows them on the defining class, even though every derived class can reference the same static member. That's why I am telling you all this, and explaining why even though you really actually want the field member in the long run, the best way to look for settable dependency properties of a given object in code is NOT to look at the listed fields!

By the way, the VS Intellisense, while not perfect, is a lot better at working this out. If for instance you type "Button.", what you'll get in completion is all the possible static members, even those static fields defined on the base classes. You'll also be "filtering" out all the instance members because you've already declared a static usage, which is a more helpful view of possibilities than the members tables, where static and instance stuff is all mucked up together. Thus, Button.WidthProperty is much more immediately at hand.

Suggestions:

1) .... uh, OK :-)

2) Working on that. See comments here.





Re: Windows Presentation Foundation (WPF) What is it in VB

rhansen

Wolf thanks for the explanation.

That all makes perfect sense and I don't have a problem with any of that.

What I am struggling with is if I want to animate any of the properties set via the Margin property i.e. Left, Right etc then how do I figure out which DP property to use. As previously mentioned I used the Canvas.Leftproperty but that was purely by playing around. It works but I don't know if it is the right DP to use.

Sorry if I seem dim but I just can't see the connection between Image and Canvas.Leftproperty or indeed why there is not an Image.Leftproperty or Image.Margin.Leftproperty or something similar.

rune





Re: Windows Presentation Foundation (WPF) What is it in VB

Wolf Schmidt - MSFT

I'll agree we have not done the most consistent job in the SDK (yet) of linking the various dependency properties to the animation classes that could possibly animate them. So you kind of have to think like the compiler, and do some link following and assume we used sensible naming patterns. This topic has a useful table for the From-To animation classes.

For your specific example: animating a Margin. The Margin dependency property takes the type Thickness. Thickness is a struct, so you can't animate its individual properties (structs are not DependencyObjects, so their individual properties can't be animated, databound, etc.) So instead, what you want to do is animate the entire Thickness. The simple animation for this is ThicknessAnimation. You give it From and To of entire Thickness structures and the animation takes care of the interpolation. There's also a key frame version.

I couldn't find any material in the SDK that animate a Thickness in code. But what you could probably do is adapt the Property Animations Sample (VB version) and change the ColorAnimation into a ThicknessAnimation, it's the same basic idea, just different types that you'd feed to the From and To, and a different target property you'd apply it to.

As far as animating Canvas.Left - you can do that too, with a DoubleAnimation, but you're really doing something different. It might well be that animating the Canvas.Left of your Image has a similar visual effect to animating the Left component of a ThicknessAnimation applied to the Margin of the Image. If that works for you, great. But in the subleties of how layout behaves, especially once you add other elements in the vicinity of your Image, there might be differences that would motivate animating the Margin for real instead. You'd probably want to play with it.





Re: Windows Presentation Foundation (WPF) What is it in VB

rhansen

Wolf,

Thanks ever so much. Thought it was me going barmy.

Quality service as always from you guys

rune