WPF: How do I set the Owner Window of a Dialog shown by a UserControl?(WPF:如何设置用户控件显示的对话框的所有者窗口?)
问题描述
我有一个包含这三种类型的 WPF 应用程序...
- 主窗口
- UserControlZack
- 窗口模式
UserControlZack1 位于我的 WindowMain...
UserControlZack1 显示一个 WindowModal 对话框...
<上一页>部分公共类 UserControlZack...私有子 SomeButton_Click(...)'实例化对话框并以模态方式打开...暗箱 As WindowModal = New WindowModal()框.所有者 = ?????box.ShowDialog()'如果对话框被接受,则处理用户输入的数据...如果 (box.DialogResult.GetValueOrDefault = True) 那么_SomeVar = box.SomeVar...万一结束子结束类
如何将 box.Owner 设置为正确的 Window,即我正在运行的 WindowMain 实例?
我不能使用 box.Owner = Me.Owner
,因为'Owner' 不是 'ProjectName.UserControlZack' 的成员."
我不能使用 box.Owner = Me.Parent
,因为它返回的是 Grid,而不是 Window.
我不能使用 box.Owner = WindowMain
,因为'WindowMain' 是一种类型,不能用作表达式."
尝试使用
.Owner = Window.GetWindow(this)
I've got a WPF application with these three types of things...
- WindowMain
- UserControlZack
- WindowModal
UserControlZack1 sits on my WindowMain...
<Window x:Class="WindowMain"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ProjectName"
...
Name="WindowMain">
<Grid>
...
<local:UserControlZack x:Name="UserControlZack1" ... />
...
</Grid>
</Window>
UserControlZack1 displays a WindowModal dailog box...
Partial Public Class UserControlZack ... Private Sub SomeButton_Click(...) 'instantiate the dialog box and open modally... Dim box As WindowModal = New WindowModal() box.Owner = ????? box.ShowDialog() 'process data entered by user if dialog box is accepted... If (box.DialogResult.GetValueOrDefault = True) Then _SomeVar = box.SomeVar ... End If End Sub End Class
How do I set box.Owner to the correct Window, my running instance of WindowMain?
I cannot use box.Owner = Me.Owner
, because "'Owner' is not a member of 'ProjectName.UserControlZack'."
I cannot use box.Owner = Me.Parent
, because that returns a Grid, not the Window.
I cannot use box.Owner = WindowMain
, because "'WindowMain' is a type and cannot be used as an expression."
Try to use
.Owner = Window.GetWindow(this)
这篇关于WPF:如何设置用户控件显示的对话框的所有者窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:WPF:如何设置用户控件显示的对话框的所有者窗口?
基础教程推荐
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- c# Math.Sqrt 实现 2022-01-01