Reputation: 285
I am writing a little Timemanagement Tool which shows when I can leave to fulfill my contractual working hours. The tool looks like this: Tool Screenshot I want to make it resizable, so i tried to set all form in relation of the window height and width. This looks like
public void resizeElements()
{
clockBody.Height = this.Height / (300/248);
clockBody.Width = this.Width / (300/248);
double marginClock = Math.Round((this.Height - clockBody.Height) / 2);
clockBody.Margin = new Thickness(marginClock);
recHr.Height = this.Height / (300 / 50);
recHr.Width = this.Width / (300/6);
recMin.Height = this.Height / (300/80);
recMin.Width = this.Width / (300 / 4);
recSec.Height = this.Height / (300/118);
recSec.Width = this.Width / (300/4);
}
As you can see in the picture the clockbody is not as big as the Window, so I tried to set it margin to Math.Round((this.Height - clockBody.Height) / 2);
but this throws an System.ArgumentException
calling:
'System.ArgumentException' in WindowsBase.dll ("'Auto,Auto,Auto,Auto' is not a valid value for property 'Margin'.")
If i edit the code like clockBody.Margin = new Thickness(26);
((300-248)/2) I can run the Application. But thats not dynamic. Any ideas?
Upvotes: 1
Views: 390
Reputation: 897
try to use ActualWidth
and ActualHeigth
properties instead of Width
and Height
.
Upvotes: 2