如何打开对话框并将其放置在父 WPF 页面的右下角?
我有一个带有按钮的基本 WPF 页面(不是窗口)。现在,当我单击按钮时,我必须打开一个模式对话框并将其放置在父级(WPF 页面)的右下角部分。
我创建了一个模式对话框,如下所示::
CDialog dialog = new CDialog();
dialog.ShowDialog();
现在我无法弄清楚如何将对话框放置在父 WPF 页面的右下角部分。 !!
编辑 1 : 我正在 CDialog 的代码隐藏中尝试这两种方法,但我得到的 Parent 为 null!
private void Window_Loaded(object sender, RoutedEventArgs e)
{
object obj = (sender as Window).Parent; //nullreference exception
}
private void Window_LayoutUpdated(object sender, EventArgs e)
{
object obj = (sender as Window).Parent; //nullreference exception
}
我应该使用哪种方法?
I have a base WPF Page (not Window) which has a Button. Now when I click on the Button, I have to open a modal dialog and place it at the bottom right part of parent(WPF Page).
I have created a modal dialog as follows ::
CDialog dialog = new CDialog();
dialog.ShowDialog();
Now I am unable to figure how to place the dialog in the bottom right part of parent WPF Page. !!
EDIT 1 : I am trying these 2 methods in codebehind of CDialog but I am getting Parent as null!!
private void Window_Loaded(object sender, RoutedEventArgs e)
{
object obj = (sender as Window).Parent; //nullreference exception
}
private void Window_LayoutUpdated(object sender, EventArgs e)
{
object obj = (sender as Window).Parent; //nullreference exception
}
Which method should I use??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下代码应该可以解决这个问题:
注意:此代码假设 child 已被渲染,因此 Actual* 属性具有正确的值。因此,将此代码放置在您知道子级已被渲染/显示的位置。
Following code should do the trick:
NOTE: this code assumes that child has been rendered and thus Actual* properties have the correct values. So, place this code in a place where you know the child has been rendered/shown.
也许您应该尝试自定义模式对话框解决方案,也许使用DispatcherFrame。
这是我为非常相似的解决方案提出的一个示例(链接文本) - 运行示例,看看我的意思:
这就是 XAML
Maybe you should try a custom modal dialog solution, perhaps using
DispatcherFrame
.Here's an example I came up with for a very similar solution (link text) - run the example, and see what I mean:
and this is the XAML