❔ 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
StackPanel stackPanel = sender as StackPanel;
stackPanel.window.DragMove();
StackPanel stackPanel = sender as StackPanel;
stackPanel.window.DragMove();
8 Replies
JakenVeina
JakenVeina2y ago
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
JakenVeina
JakenVeina2y ago
which this class provides helper methods for
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
JakenVeina
JakenVeina2y ago
uhh? in MainWindow code... wouldn't that just be this?
Anchy
Anchy2y ago
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
Accord
Accord2y ago
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.
Want results from more Discord servers?
Add your server