Click here to Skip to main content
13,141,576 members (53,098 online)
Click here to Skip to main content
Add your own
alternative version


1 bookmarked
Posted 16 Feb 2010

No Scroll content of WPF XBAP in iframe

, 16 Feb 2010
Rate this:
Please Sign up or sign in to vote.
No Scroll content of WPF XBAP in iframe

In my previous blog post, I discussed how to hide the navigation UI of xbap while you host Xbap (XAML browser application) in iframe. Note that xbap can be accessed directly from browser's URL address and can also be viewed in an iframe in an existing web site. In both cases, a user can have contents that require scrolling. If user developed the xbap application in such a way that the application will be accessed directly form URL address, the user can archive the goal by adding a "scrollableview" element in your XAML page. A code sample is provided below:

<Page x:Class="CookieTest.Page1"



			 <!--<span class="code-comment">your content will go here--></span>

Next case is if user hosted the xbap application in an iframe. In this case, there is a good chance that the user will be viewing two vertical scrollbars in user's browser if user's existing site's page is long enough to cause view a vertical scroll bar, that is the browser's vertical scrollbar. Xbap host have a defined size, which generally as long and wide as the browser window. So if your content is longer than the size of xbap host, you can lose your content from viewable content area, or you will end up having two scrollbars. Well, there are several solutions to this problem. Let's discuss with a simpler version. Make the iframe's height property as long as the xbap that is hosting the xbap. And make sure that your xbap will not grow larger than that. But if your xbap has variable content and has variable height and you got to keep the constant look, you need to do some engineering to keep things smooth. Xbap supports get and set of cookie in the site of origin. So do calculate your height for your content in xbap and then set the height as a cookie, make sure you do set the height of the content as a cookie each time the content of xbap has changed, of course in case of the content that cause the xbap to change its size. Here is a code example to set cookie for site from xbap.

Application.SetCookie(BrowserInteropHelper.Source, "HEIGHT=" + DemoHeight );

Now in the page, where you hosted your xbap in iframe read the cookie with JavaScript and then change the height of the iframe. That's it! You will have a smooth operation of auto grow or shrink of your xbap and won't cause any extra scrollbar. For reading the cookie does a little engineering, for example, always track the height cookie with JavaScript timer based function.

<script language="javascript" type="text/javascript">

function getCookie(c_name)
	if (document.cookie.length>0)
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)
			c_start=c_start + c_name.length+1;
			if (c_end==-1) c_end=document.cookie.length;
				return unescape(document.cookie.substring
	return "";

function InCreaseHeight()
	var hight = getCookie('HEIGHT');
	if(hight != "")
				hight = 600;
			document.getElementById('framename').height = hight;


One more thing to do is call the JavaScript increase height function on body on load event of the page to kickstart the process.

<body onload="InCreaseHeight();">



This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Rahman Masudur
Software Developer Riteq
Australia Australia
About Md. Masudur Rahman

Masudur currently works at Riteq as a software developer. Masudur Lives in Sydney, Australia.


26 May 2009: Monthly competition: Best ASP.NET article of April 2009

24 Mar 2009: Monthly competition: Best ASP.NET article of February 2009

Masudur Blog

Masudur put down his interesting learning experiences in his blog at

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170915.1 | Last Updated 16 Feb 2010
Article Copyright 2010 by Rahman Masudur
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid