Windows get parent window

Свойство Window. Парентвиндов (Visio) Window.ParentWindow property (Visio)

Возвращает объект Window , который является родительским для другого объекта Window . Returns the Window object that is the parent of another Window object. Только для чтения. Read-only.

Синтаксис Syntax

выражение. expression. ParentWindow

Expression (выражение ) Переменная, представляющая объект Window . expression A variable that represents a Window object.

Возвращаемое значение Return value

Примечания Remarks

Парентвиндов возвращает Nothing и не вызывает исключение, если окно является окном верхнего уровня. ParentWindow returns nothing and raises no exception if the window is a top-level window. Окно верхнего уровня является членом коллекции Windows объекта Application . A top-level window is a member of the Windows collection of an Application object.

Используйте свойство Parent объекта Window , чтобы получить коллекцию Windows , к которой принадлежит объект Window . Use the Parent property of a Window object to get the Windows collection to which a Window object belongs.

Поддержка и обратная связь Support and feedback

Есть вопросы или отзывы, касающиеся Office VBA или этой статьи? Have questions or feedback about Office VBA or this documentation? Руководство по другим способам получения поддержки и отправки отзывов см. в статье Поддержка Office VBA и обратная связь. Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.

WPF Get parent window

In my MainWindow.xaml.cs file I made a getter to get the reference to my listbox.

Now I want to access the LoggerList from a normal class but I don’t work. I tried the following:

But this only works in a *xaml.cs file and not in a normal *.cs file.

Читайте также:  Перестал работать microsoft edge windows 10

1 Answer 1

There are a number of ways of accessing Window s in WPF. If you have several open, then you can iterate through them like this:

If you had a particular type of custom Window , you could use this:

If you are just after a reference to the MainWindow , then you can simply use this:

However, using this method, there is a chance that it will return null . In this case, make sure that you set the MainWindow to this property in it’s constructor:

It should be noted however, that @woutervs is correct. you should not be accessing UI controls from Window s in library classes. You really should data bind collections to the ListBox.ItemsSource and then manipulate the data collection instead.

I don’t know why your Application.Current object is null . it could be because you’ve loaded your class library into a different AppDomain . Either way, I think that you are missing the big picture. There really is no reason why a class library class should need a reference to the main Window .

If you need to perform some work on the data collection, then just pass the data collection from code behind, or your view model. Once the work is complete, then just pass it back to the UI where you have access to the ListBox and/or the collection that is data bound to the ItemsSource property.

Get Parent directory of a specific path in batch script

Hi I have full file path in a variable of batch file. How to get its first and second level parent directory path?

dppath% work? I know it works for numbered args (%

dp1). – Andy Nugent Jan 22 ’16 at 9:09

3 Answers 3

do not use variable PATH for this. %PATH% is a built-in variable used by the command prompt.

dpa» ; you are removing the trailing backslash, which might be problematic in case the first-level parent is already the root of a drive, because the loop would receive e. g. D: , which means the current directory of drive D: ; my suggestion returns the root of drive D: . – aschipfl Jan 22 ’16 at 14:01

Читайте также:  Linux terminal how to root

As npocmaka correctly suggests, pick a different variable from %PATH% (or any of these other environment variables). Secondly, make sure your script uses setlocal to avoid junking up your console session’s environment with the variables in this script. Thirdly, just add a \.. for each ancestor you want to navigate. No need to bother with substring manipulation.

0,-1% – mwag Oct 3 ’20 at 14:35

It is possible to get the file first parent (base dir) using a small subroutine that returns a

dp path to a file, :GetFileBaseDir and :GetFileBaseDirWithoutEndSlash in the example below.

Thank to @rojo for a way to achive the goal for multiple parents. I’ve enveloped his solution in a subroutine :GetDirParentN to make it more useful.

Win32 window Owner vs window Parent?

In Win32 programming, what is the difference between a window’s parent and a window’s owner? I thought I had it figured out, then I came across this code:

This actually sets the window’s owner, not the parent — despite the GWL_HWNDPARENT being used. Are the terms parent/owner interchangeable, or is there actually a difference?

4 Answers 4

Owner is the Window* responsible for a control or dialog (for example, responsible for creating/destroying the window).

Parent is the next-senior window* to a control or dialog in the window chain, but isn’t actually responsible for it (doesn’t necessarily care about its lifecycle, etc). A window’s parent can also be its owner.

*Window vs window: Window is an actual window displayed on the screen; window is any object with a HWND (includes buttons, panels, etc).

Ownership is a relationship between two top level windows while Parent is a relationship between a top level and a WS_CHILD, or a WS_CHILD and another WS_CHILD.

Читайте также:  Удаленный редактор реестра windows

The parent of a button is the form it is on, while a message box is owned by the form that showed it.

Read this article from Microsoft Win32 Window Hierarchy and Styles to get a much clearer understanding of Ownership, Parenting, ZOrder, SetWindowLong, GetWindow and all the other nasty bits of the Win32 api for creating window relationships.

EDIT: Looks like Microsoft took down that content, here is another reasonable summary of Ownership / Parenting.

Win32 window Owner vs window Parent?

In Win32 programming, what is the difference between a window’s parent and a window’s owner? I thought I had it figured out, then I came across this code:

This actually sets the window’s owner, not the parent — despite the GWL_HWNDPARENT being used. Are the terms parent/owner interchangeable, or is there actually a difference?

4 Answers 4

Owner is the Window* responsible for a control or dialog (for example, responsible for creating/destroying the window).

Parent is the next-senior window* to a control or dialog in the window chain, but isn’t actually responsible for it (doesn’t necessarily care about its lifecycle, etc). A window’s parent can also be its owner.

*Window vs window: Window is an actual window displayed on the screen; window is any object with a HWND (includes buttons, panels, etc).

Ownership is a relationship between two top level windows while Parent is a relationship between a top level and a WS_CHILD, or a WS_CHILD and another WS_CHILD.

The parent of a button is the form it is on, while a message box is owned by the form that showed it.

Read this article from Microsoft Win32 Window Hierarchy and Styles to get a much clearer understanding of Ownership, Parenting, ZOrder, SetWindowLong, GetWindow and all the other nasty bits of the Win32 api for creating window relationships.

EDIT: Looks like Microsoft took down that content, here is another reasonable summary of Ownership / Parenting.

Оцените статью