punker76 / MahApps.Metro.SimpleChildWindow

A simple child window for MahApps.Metro
MIT License
374 stars 55 forks source link

ChildWindow position when it appears. #103

Closed DeputyOfCopyPaster closed 4 years ago

DeputyOfCopyPaster commented 4 years ago

hello everyone! Is there a way to set a certain ChildWindow position when it appears? At the moment it appears exact in the middle of the screen and even I move it to a certain place, next time (after App restart), it appears in the middle of the screen as it was before. Is there a way to save this position?

thanks in advance!

timunie commented 4 years ago

Hi @DeputyOfCopyPaster If I remember correctly you can use the Margin property to define the position of a child window. I don't have a PC at the moment so i could not check it right now.

Happy coding Tim

DeputyOfCopyPaster commented 4 years ago

Hi @DeputyOfCopyPaster If I remember correctly you can use the Margin property to define the position of a child window. I don't have a PC at the moment so i could not check it right now.

Happy coding Tim

I don't think so, the Margin isn't a proper way to do that. The ChWindow isn't a static control. There should be a cleverer way, definetely. So, please check it and tell me how to do that by a proper way. I'm just out of any ideas.

thanks in advance!

timunie commented 4 years ago

Hi @DeputyOfCopyPaster , I had a look in the source code and as far as I can see (I'm not a programmer ;-) ) there is currently no buit in way to save the window position...

Workaround You are correct, it wasn't Margin that I was looking for, it was Padding. You can take this property as a work around: Let`s assume you have the following parameters set:

 VerticalContentAlignment = VerticalAlignment.Top;
 HorizontalContentAlignment = HorzontalAlignment.Left;

When you close the ChildWindow you have to calculate the offset from left and top and save these value somewhere, e.g. in the Properties. When you call the ChildWindow again, you can then initilize it with these values:

Padding = new Thickness(SavedLeftPosition, SavedTopPosition, 0, 0);

But please keep in mind, the MainWindow may have changed it's size and the ChildWindow might be outside of the MainWindow. This has to be cached I think.

Built in soultion As far as I can see there has to be two new Properties OffsetX and OffsetY to enable what you are looking for. I don't know if @punker76 wants this feature or not. If he gives me the go, I will try to implement these Properties.

Happy coding Tim

DeputyOfCopyPaster commented 4 years ago

@timunie, hello

Hi @DeputyOfCopyPaster , I had a look in the source code and as far as I can see (I'm not a programmer ;-) ) there is currently no buit in way to save the window

I'm just a deputy of CopyPaster and CopyPaster itself is one of deputies of true Programmer. ;) I will test those new properties soon.

thanks a lot!

timunie commented 4 years ago

Hi @DeputyOfCopyPaster ,

I took another gif to show you that it is possible to remember the position (I see you got it and changed your question, but I am already done with the new gif :-) ).

ChildWindow_RememberPosition

Happy coding Tim

DeputyOfCopyPaster commented 4 years ago

@timunie, hi there Yes I've got (not at once :)) that you did exactly what I meant. So I had changed my post. Could you tell me where have you done changes? ChWindow version? release

timunie commented 4 years ago

@DeputyOfCopyPaster, at the moment it is just a PR. I don't know if it will be ever available, @punker76 has to decide :+1: or :-1:

DeputyOfCopyPaster commented 4 years ago

Why not? Missing of that just deprives ChWindow of some usability, I believe. The ChWindows must pop up at place where it was planned by end user. :+1:

timunie commented 4 years ago

I am not the owner of this repro and don't have write permissions, so I am unable to do.

DeputyOfCopyPaster commented 4 years ago

never mind, hope owners follow our chat...

DeputyOfCopyPaster commented 4 years ago

@timunie, @punker76, Guys, I am not familiar with Github system at all, so please enlighten me what is the status of this ChWindow feature. May I use it? Or?

thank you!

timunie commented 4 years ago

@DeputyOfCopyPaster yes if you uae the latest prerelease

DeputyOfCopyPaster commented 4 years ago

@DeputyOfCopyPaster yes if you uae the latest prerelease

@timunie, How do I find the latest prerelease? I mean where is prerelease located?

timunie commented 4 years ago

Hi @DeputyOfCopyPaster ,

sorry for the late replay. Set this checkmark in your Nuget-Manager: image

Happy testing Tim

DeputyOfCopyPaster commented 4 years ago

@timunie, hi there, just have assembled a test project based on yours all latest prereleases, as you had showed me above. Perhaps I have missed something. The ChildWindow still doesn't remember its previous position. A missed parameter in ChWindow_01.xaml? Today is Monday, though... :)

ChWindow_01

timunie commented 4 years ago

Hi @DeputyOfCopyPaster , As you can have more than one CW that you might want to rember, there is no build in way to save the position. You will need to save OffsetX and OffsetY on your own. see: https://docs.microsoft.com/de-de/visualstudio/ide/managing-application-settings-dotnet?view=vs-2015&redirectedfrom=MSDN

Happy coding Tim

DeputyOfCopyPaster commented 4 years ago

@timunie, it seems I've gotten a remembering of ChWindow previous position. However, why I'm getting at left upper corner -negative values and at right lower corner -positive values? As per GIF attached. Please give me an idea. Normally they should be positive within mother's window.

neg_values

timunie commented 4 years ago

@DeputyOfCopyPaster it depends on the HorizontalAlignment and VerticalAlignment

DeputyOfCopyPaster commented 4 years ago

@timunie. I don't see any alignment properties used in your latter demo release.

timunie commented 4 years ago

the default is center, so the Point (0,0) is in the middle ...

DeputyOfCopyPaster commented 4 years ago

@timunie, while playing around I've noticed one more thing which brings some discomfort in ChildWindow usage. As practice shows, the left upper ChildWindow's corner (mostly it's icons area) is not sensitive for dragging. In other words it doesn't allow to hide ChildWindow more deeper. It's possible to hide a bit more, though. @timunie, look, I'm not speaking about hiding entirely, I'm speaking about hiding a bit more than we can at the moment. So, my question is, is there a way to leave icon at its place and get icon's area to be sensitive for dragging?

So, what do you think about?

ChWindow_icon

timunie commented 4 years ago

to be honest I don't see a reason why one should move the childwindow out of the parent window. Maybe you should consider to open a new MetroWindow.

Happy dragging Tim

DeputyOfCopyPaster commented 4 years ago

to be honest I don't see a reason why one should move the childwindow out of the parent window. Maybe you should consider to open a new MetroWindow.

Happy dragging Tim

@timunie, Yeah, I see you don't know. However, many end users know some reasons. Since the ChildWindows are essentially dialogues, what would you do with a few annoying dialogues which pop up for some reasons every 5 seconds on your screen, for example? Our end users just hide them nearly out of the screen. So, in terms of usabiliity the dragging here is realized pretty poorly.

In other words the icon must not interfere to happy dragging of end users.

DeputyOfCopyPaster commented 4 years ago

@timunie, I decided to make some changes and set the property IsOpen="true", and have seen the following stuff, as per image attached. Perhaps you now how to put ChildWindow in the center of so-called "design-time". For some reasons it always located not in the middle. I've tried to apply different kinds of allignments. It didn't affect.

Xaml_designer

timunie commented 4 years ago

@DeputyOfCopyPaster please try:

HorizontalContentAlignment="Right"
VerticalContentAlignment="Bottom"

But please keep in mind that even this will not solve all the positioning issues you might have. And unfortunatally I don't have the time to rewrite all the stuff needed to archiev your goal.

One personal oppinion from my side: If I were your customer and the ChildWindow would open so often, I would ask if this is the right Control / UserInterface for what you are trying to archiev. We can discuss this in a private gitter room, if you want to, please not here.

I hope you understand that I will now leave this issue as it is right now.

Happy coding Tim