In my previous blog post, I discussed about how to hide the navigation UI of XBAP while hosting XBAP (XAML browser application) in IFrame. Note that XBAP can be accessed directly from a browser using a URL address and can also be viewed in an IFrame in an existing web site. In both cases, the user can have contents that require scrolling. If the user develops the XBAP application in such a way that the application will be accessed directly form a URL address, the user can archive the goal by adding a "
scrollableview" element in your XAML page. Shown below is a code sample.
1: <Page x:Class="CookieTest.Page1"
The next case is if the 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 the user's browser if the user's existing page is long enough to cause a vertical scroll bar to appear, that is the browser's vertical scrollbar. XBAP host has a defined size, which generally is as long and wide as the browser window. So if your content is longer than the size of the XBAP host, you can lose your content from the viewable content area. Or you will end up having two scrollbars. Well, there are several solutions to this problem. Let's discuss a simpler version. Make the IFrame's height property as long as 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 getting and setting of cookies 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 set the height of the content as a cookie each time the content of XBAP has changed. Of course, in the case of the content that causes XBAP to change its size. Here is a code example to set the cookie for a site from XBAP:
Application.SetCookie(BrowserInteropHelper.Source, "HEIGHT=" + DemoHeight );
2: function getCookie(c_name)
4: if (document.cookie.length>0)
6: c_start=document.cookie.indexOf(c_name + "=");
7: if (c_start!=-1)
9: c_start=c_start + c_name.length+1;
11: if (c_end==-1) c_end=document.cookie.length;
12: return unescape(document.cookie.substring(c_start,c_end));
15: return "";
17: function InCreaseHeight()
19: var hight = getCookie('HEIGHT');
20: if(hight != "")
26: hight = 600;
28: document.getElementById('framename').height = hight;
1: <body onload="InCreaseHeight();">