Page view counter
Resize TabControl with Page_SizeChanged Event. Subscribe to this thread
Last post 12-09-2008 10:53 AM by NearDeath. 2 replies.
Sort Posts:
12-08-2008 5:47 PM
Resize TabControl with Page_SizeChanged Event.

All, I am having an issue getting my tabcontrol to resize when the web browser is resized.

Here is the block of code doing the resizing... Basically what I am doing is calculating the percentage of screen change and then attempting to resize the control based on the percentage of screen change. If I don't put in any specific code to do the resizing of the tab control, it resizes the the tab control border only, but none of the content therein gets resized, such as textboxes, labels, and tabs themselves. I have a "UserControl" which has the tab control in it and I add the usercontrol to the root datagrid.

Currently, the below code kind of works, but for some odd reason, the tab control does not size correctly with the page resize. When you shrink the page, the tabcontrol is shrinking a lot more than the rest of the page percentage wise, so that the tab control on full size looks correct, but when shrinking, it no longer fills up the screen and just takes up a small portion of the screen that is left. It almost looks like my mathmatics below is wrong, but it looks right to me.

Any suggestions?

 Thanks ahead of time... Maurice 

 

if (e.NewSize.Width < _originalWidth ||

e.NewSize.Height < _originalHeight)

{

PageScale.ScaleX = 1.0;

PageScale.ScaleY = 1.0;

}

else

{

if (e.NewSize.Width / e.NewSize.Height > _originalAspectRatio)

{

PageScale.ScaleY = 1.0;

PageScale.ScaleX = 1.0;

}

else

{

PageScale.ScaleX = e.NewSize.Width / _originalWidth;

PageScale.ScaleY = e.NewSize.Height / _originalHeight;

}

}

double dbl_widthDifference = _originalWidth - e.NewSize.Width;

double dbl_heightDifference = _originalHeight - e.NewSize.Height;

double dbl_widthPercent = dbl_widthDifference / _originalWidth;

double dbl_heightPercent = dbl_heightDifference / _originalHeight;

double dbl_finalWidth = 1.0 - dbl_widthPercent;double dbl_finalHeight = 1.0 - dbl_heightPercent;

cntrlScaleTransform.ScaleX = dbl_finalWidth;

cntrlScaleTransform.ScaleY = dbl_finalHeight;

m_tabCntrlMainContent.RenderTransform = cntrlScaleTransform;

 

 

 

NearDeath

Loading...
Joined on 08-21-2008
Posts 7
12-08-2008 6:53 PM
Marked as Answer
Re: Resize TabControl with Page_SizeChanged Event.

 When the "filling" isn't correct, add a breakpoint in this part of the code and check the running numbers. You'll find there's Panel derived class (probably a Grid) that is not returning the correct values.

These classes are yet long from clean in Silverlight. For instance, I've found some cases where the Grid control returns different sizes depending on having or not a Background set.

Bigsby

Loading...
Joined on 07-19-2007
Lisboa, Portugal
Posts 68
12-09-2008 10:53 AM
Re: Resize TabControl with Page_SizeChanged Event.

 

Thanks, I will check that as well and see if I see anyting... If anyone else has any other ideas, let me know... :)
NearDeath

Loading...
Joined on 08-21-2008
Posts 7
Microsoft Communities