标签: c# wpf rectangles ellipse
如何检查创建Rectangle或Ellipse的对象是否在WPF中?
Ellipse ellipse = new Ellipse(); Rectangle rect = new Rectangle(); if (rect.getType()){ rect.Margin = new Thickness(x,y,0,0); } else { ellipse.Margin = new Thickness(x, y, 0, 0); }
答案 0 :(得分:3)
使用is keyword,您可以检查对象的类型。
is
if(rect is Rectangle)