Silverlight ChildWindow 无法正确重新定位

发布于 2024-10-27 03:49:09 字数 547 浏览 2 评论 0原文

我正在使用 ChildWindow (Silverlight),它还包含一些扩展器控件。在一种情况下,当扩展器控件展开时,子窗口的底部会向下展开到底部的屏幕之外,但仍然在顶部留出空间。

如何重新定位子窗口以便将其置于屏幕中央,就像我刚刚打开子窗口一样? (这很容易,但我认为不可行)

(手动干预) 我已经完成了 ContentRoot 的 RenderTransform,并且该集合中有 6 个转换,其中 2 个是 TranslateTransform。如果我更新第一个的 X/Y 属性(不知道应该更改这两个属性中的哪一个)并使用整个 TransformGroup 更新 RenderTransform 属性,我可以成功地在屏幕上移动 ChildWindow - 但事实并非如此表现得像我期待的那样。

我也不知道为什么当 Expander 控件展开时,ChildWindow_SizeChanged 事件不会触发。窗口的大小确实发生了变化,那么为什么它不触发呢?

好的 - 问题太多了,只需要回答第一个问题,剩下的就是补充我对 WPF/Silverlight 是如何工作的知识...

问候, 理查德

I am using the ChildWindow (Silverlight) which also contains some expander controls. In one case, when the expander control expands, the bottom of the child window expands down out the screen on the bottom, but still leaves room on the top.

How can I re-position a child window in order to center it in the screen, as if I just opened the childwindow? (That would be easy, but I don't think doable)

(manual intervention)
I've gone through RenderTransform of the the ContentRoot, and I have six transforms in that collection, 2 of which are TranslateTransforms. If I update the X/Y properties of the first one (don't know which of the two I should be changing) AND update the RenderTransform property with the entire TransformGroup, I have success in moving the ChildWindow around the screen - but it's not behaving as I am expecting.

I also dont' know why the ChildWindow_SizeChanged event does not fire, when the Expander control expands. The window does change in size, so why does it not fire?

Ok - too many questions, just need the first one answered, the rest are to fill in my knowledge of how WPF/Silverlight is working...

Regards,
Richard

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

顾铮苏瑾 2024-11-03 03:49:09

通过此博客回答:http://www. kunal-chowdhury.com/2010/11/how-to-reposition-silverlight-child.html

/// <summary>
/// Centers the Silverlight ChildWindow in screen.
/// </summary>
/// <remarks>
/// 1) Visual TreeHelper will grab the first element within a ChildWindow - this is the Chrome (Title Bar, Close button, etc.)
/// 2) ContentRoot - is the first element within that Chrome for a ChildWindow - which is named this within the template of the control (Childwindow)
/// 3) Using the container (named ContentRoot), pull out all the "Transforms" which move, or alter the layout of a control
///   TranslateTransform - provides X,Y coordinates on where the control should be positioned
/// 4) Using a Linq expression, grab teh last TransLateTransfrom from the TransformGroup
/// 5) Reset the TranslateTransform to point 0,0 which should reference the ChildWindow to be the upper left of the window.  However, this is setting
///    is probably overridden by a default behaviour to always reset the window window to the middle of the screen based on it's size, and the size of the browser
///    I would have liked to animate this, but this likely requires a storyboard event that I don't have time for at this moment.
///    
/// This entire process to move, or alter a window in WPF was a total learning experience.
/// </remarks>
/// <param name="childWindow">The child window.
public static void CenterInScreen(this ChildWindow childWindow)
{
  var root = VisualTreeHelper.GetChild(childWindow, 0) as FrameworkElement;
  if (root == null) { return; }

  var contentRoot = root.FindName("ContentRoot") as FrameworkElement;
  if (contentRoot == null) { return; }

  var transformgroup = contentRoot.RenderTransform as TransformGroup;
  if (transformgroup == null) { return; }

  TranslateTransform transform = transformgroup.Children.OfType<TranslateTransform>().LastOrDefault();
  if (transform == null) { return; }

  transform.X = 0;
  transform.Y = 0;

}

}

Answer via this blog: http://www.kunal-chowdhury.com/2010/11/how-to-reposition-silverlight-child.html

/// <summary>
/// Centers the Silverlight ChildWindow in screen.
/// </summary>
/// <remarks>
/// 1) Visual TreeHelper will grab the first element within a ChildWindow - this is the Chrome (Title Bar, Close button, etc.)
/// 2) ContentRoot - is the first element within that Chrome for a ChildWindow - which is named this within the template of the control (Childwindow)
/// 3) Using the container (named ContentRoot), pull out all the "Transforms" which move, or alter the layout of a control
///   TranslateTransform - provides X,Y coordinates on where the control should be positioned
/// 4) Using a Linq expression, grab teh last TransLateTransfrom from the TransformGroup
/// 5) Reset the TranslateTransform to point 0,0 which should reference the ChildWindow to be the upper left of the window.  However, this is setting
///    is probably overridden by a default behaviour to always reset the window window to the middle of the screen based on it's size, and the size of the browser
///    I would have liked to animate this, but this likely requires a storyboard event that I don't have time for at this moment.
///    
/// This entire process to move, or alter a window in WPF was a total learning experience.
/// </remarks>
/// <param name="childWindow">The child window.
public static void CenterInScreen(this ChildWindow childWindow)
{
  var root = VisualTreeHelper.GetChild(childWindow, 0) as FrameworkElement;
  if (root == null) { return; }

  var contentRoot = root.FindName("ContentRoot") as FrameworkElement;
  if (contentRoot == null) { return; }

  var transformgroup = contentRoot.RenderTransform as TransformGroup;
  if (transformgroup == null) { return; }

  TranslateTransform transform = transformgroup.Children.OfType<TranslateTransform>().LastOrDefault();
  if (transform == null) { return; }

  transform.X = 0;
  transform.Y = 0;

}

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文