Click here to Skip to main content
Click here to Skip to main content

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"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Page1">
	<ScrollViewer>
		<Grid>
			 <!--<span class="code-comment">your content will go here--></span>
		</Grid>
	</ScrollViewer>
</Page>

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;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
				return unescape(document.cookie.substring
							(c_start,c_end));
		}
	}
	return "";
}

function InCreaseHeight()
{
	var hight = getCookie('HEIGHT');
	if(hight != "")
	{
		if(document.getElementById('framename')!=null)
		{
			if(hight<600)
			{
				hight = 600;
			}
			document.getElementById('framename').height = hight;
		}
	}
	setTimeout("InCreaseHeight()",250);
}  

</script>  

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();">

References

License

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 (Senior) Satori Tech Solutions, Inc.
Australia Australia
About Md. Masudur Rahman
 
Masudur currently works at Satori Tech Solutions, Inc. as a software developer. Masudur Lives in Sydney, Australia.
 
Awards
 
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 http://munnaondotnet.blogspot.com/.

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 16 Feb 2010
Article Copyright 2010 by Rahman Masudur
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid