V
V
Vladislav Dyuzhev2020-05-07 19:10:59
WPF
Vladislav Dyuzhev, 2020-05-07 19:10:59

How to access the MainWindow element from WPF Page code?

Hello. I have a MainWindow window, inside there is a Frame, in which the pages are displayed. With a certain action on the page, I need to change the element belonging to the MainWindow. I searched for a long time, but did not find a solution. I'm just learning wpf, please suggest possible alternatives if it's not possible.
In short, this is a simple audio player:
There is a page with playlists (There's just a DataGrid)
When a playlist is selected in the Frame, a page with audio files (also a DataGrid) is displayed.
Actually, when you select an audio file, you need to start playing, but all controls (the Play/Pause/Stop buttons and the Slider that displays progress) are off the page, in the main window (this is done so that when switching between pages, the playback of the selected audio file does not stop). The problem is that the audio file selection event handler (which resides in the separate page code file) needs to interact with elements that are outside the page. Perhaps this is a consequence of poor design, but still I want to finish at least this way. Thanks in advance

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Peter, 2020-05-07
@TheAnubisGod

The easiest way to get to MainWindow is:
Application.Current.MainWindow
But it all depends on the design pattern of your application, there may be other solutions for the MVVM example.

D
d-stream, 2020-05-07
@d-stream

Now I would like to see the xaml, but it's still completely incomprehensible. But in the abstract - use binding. However it is possible and triggers.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question