❔ How to get the main window from a custom control?
I am trying to make a custom top bar instead of wpfs defualt minimize maximize and drag buttons however when i type drag move into my stackpannel mousedown it says it does not exist
maybe there is a way to do something like this
8 Replies
there's probably a better way to accomplish what you're wanting, but if there is, I don't know of it
the direct thing to do is walk the visual tree
VisualTreeHelper Class (System.Windows.Media)
Provides utility methods that perform common tasks involving nodes in a visual tree.
which this class provides helper methods for
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
uhh?
in
MainWindow
code... wouldn't that just be this
?I think they are referring to some kind of singleton pattern where you have a public static instance of MainWindow
I also would just walk the visual tree, however when implementing a custom top-bar I would either create a custom Window or just implement DragMove into the code-behind for the window on the MouseDown event for the custom top-bar
You could also just use one of the many styling libraries for WPF which allow you to have a custom window chrome
$wpfuilibs
MahApps
https://github.com/MahApps/MahApps.Metro
ModernWPF
https://github.com/Kinnara/ModernWpf
Adonis UI
https://github.com/benruehl/adonis-ui
Material Design
https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit
Biaui
https://github.com/YoshihiroIto/Biaui
HandyControl
https://github.com/HandyOrg/HandyControl
WPFUI (Windows 11 inspired)
https://github.com/lepoco/wpfui
Waves (WPF/Avalonia/More)
https://github.com/waves-framework/waves.ui.wpf
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.