gpt4 book ai didi

.net - WPF:如何设置用户控件显示的对话框的所有者窗口?

转载 作者:行者123 更新时间:2023-12-03 05:52:35 26 4
gpt4 key购买 nike

我有一个包含这三种类型的 WPF 应用程序...

  • 主窗口
  • 用户控制扎克
  • 窗口模式

UserControlZack1 位于我的 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 显示 WindowModal 对话框...

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 SubEnd Class

如何将 box.Owner 设置为正确的 Window(我正在运行的 WindowMain 实例)?

我无法使用 box.Owner = Me.Owner,因为“'Owner' 不是 'ProjectName.UserControlZack' 的成员。”

我无法使用 box.Owner = Me.Parent,因为它返回一个网格,而不是窗口。

我无法使用 box.Owner = WindowMain,因为“'WindowMain' 是一种类型,不能用作表达式。”

最佳答案

尝试使用

.Owner = Window.GetWindow(this)

关于.net - WPF:如何设置用户控件显示的对话框的所有者窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/607370/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com