开发者

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

I have a question . What is the difference between Canvas.SetTop(objFrameworkElement,10); and objFrameworkEle开发者_如何学Pythonment.SetValue(Canvas.TopProperty,20)


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜