views:

14

answers:

2

I have a question . What is the difference between Canvas.SetTop(objFrameworkElement,10); and objFrameworkElement.SetValue(Canvas.TopProperty,20)

A: 

It's basically the same thing. Canvas.SetTop calls SetValue on the element. There are sometimes a bit of logic in the SetX methods, like calling ClearValue instead of SetValue if the specified value is the same as the default value (that's not the case for Canvas.Top). So I prefer using the GetX/SetX methods.

Julien Lebosquain
Sorry but in didn't get your answer. I was also knowing that these are same but I was asked a question to explain the difference and I was not able to .So please can you elaborate your answer. Thank you
Divya prakash
+1  A: 

For the most part you can use either approach interchangeably. The key difference is that Canvas.SetTop uses the specific type Double for the value parameter whereas SetValue uses Object.

Hence using things like SetTop is a better practice when you know the property you actually want to set. You'll get compile time errors when you're passing the wrong type whereas using SetValue you won't know of the error until runtime.

AnthonyWJones
Thanks I think this answers my question.
Divya prakash