将对象“从文档流中取出”在Silverlight中,和CSS绝对定位效果一样吗?
使用 Silverlight 4 时,是否可以将图像设置为绝对位置,并将其带出文档流,从而允许其自由定位于任何网格等?
使用CSS,您可以将元素设置为使用绝对定位,然后它将根据其上方的第一个相对父级进行绝对定位。
我希望能够将图像放置在屏幕上的任何位置,页面上任何其他内容的上方,但在 Silverlight 中。
我尝试了绝对定位(在后面的代码中),它似乎没有正确定位,看起来好像它默认为水平对齐和垂直对齐 “中心”
CustomIcon.Source = new BitmapImage(new Uri("http://media.trueachievements.com/imagestore/0000149800/149834.jpg", UriKind.Absolute));
CustomIcon.SetValue(Canvas.LeftProperty, Pt.X);
CustomIcon.SetValue(Canvas.TopProperty, Pt.Y);
CustomIcon.Visibility = System.Windows.Visibility.Visible;
Pt 在其他地方设置正确(调试时检查这一点)。
该图像位于设置了 x:Name 属性的 Xaml 中,并且默认设置为“折叠”可见性。
如果使用 Silverlight 4 可以获得与我描述的相同的效果(CSS),有什么想法吗?
When using Silverlight 4, is it possible to set an Image to an absolute position, and bring it out of the document flow, allowing it to be positioned freely of any grids etc?
With CSS you can set an element to use absolute positioning, and then it will be positioned absolute, based on the first relative parent above it.
I want to be able to place an Image, anywhere on the screen, above anything else on the page, but in Silverlight.
I tried absolute positioning (In the code behind) and it doesn't seem to be positioned correctly, it looks as though it defaults to both Horizontal Alignment and Vertical alignment as
"Centre"
CustomIcon.Source = new BitmapImage(new Uri("http://media.trueachievements.com/imagestore/0000149800/149834.jpg", UriKind.Absolute));
CustomIcon.SetValue(Canvas.LeftProperty, Pt.X);
CustomIcon.SetValue(Canvas.TopProperty, Pt.Y);
CustomIcon.Visibility = System.Windows.Visibility.Visible;
Pt is set correctly elsewhere (Checked this when Debugging).
The image is in the Xaml with the x:Name attribute set, and is set to Collapsed visibility by default.
Any ideas if it's possible to get the same effect I described (CSS) but using Silverlight 4?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仅当您实际将控件添加到
Canvas
元素时,画布 Left 和 Top 附加属性才有效。只需将
Canvas
元素添加到您的 xaml 中作为“LayoutRoot”网格中的最后一个元素即可。您无需设置其宽度或高度,也不应将其设置为 Grid.Row 或 Column。现在,当您将项目添加到此画布时,它们可以放置在任何位置。
The canvas Left and Top attached properties only have an effect if you actually add the control to an
Canvas
element.Just add a
Canvas
element to your xaml as the last element in the "LayoutRoot" grid. You do not need to set its width or height nor should you set it Grid.Row or Column.Now when you add items to this canvas they can be positioned anywhere.