Click here to Skip to main content
13,293,698 members (70,060 online)
Click here to Skip to main content
Add your own
alternative version


2 bookmarked
Posted 4 May 2010

Silverlight XPS Viewer in SL4, Support viewbox and viewport property

, 4 May 2010
Rate this:
Please Sign up or sign in to vote.

During my development last week I was working on a Silverlight based XPS viewer. During this viewer we came to a situation in which an XPS was made from power point slide. In that PPT two images were shown during rendering the images present in it.

The problem is that Silverlight doesn’t have any viewport or viewbox support. Along with these problems, the font files need to be downloaded externally so that we can render them in our XPS Viewer

Using the code

Now i have replace path into Image element, remove 1st image and change left and top to 2nd image plus increase hight.

<br />
<pre><br />
<br />
// crate 2 rect, one of viewbox and 2nd is viewport<br />
var viewbox = new Rect(Convert.ToDouble(tempviewbox[0]), Convert.ToDouble(tempviewbox[1]),<br />
                                Convert.ToDouble(tempviewbox[2]), Convert.ToDouble(tempviewbox[3]));<br />
<br />
var viewport = new Rect(Convert.ToDouble(tempviewPort[0]), Convert.ToDouble(tempviewPort[1]),<br />
                                 Convert.ToDouble(tempviewPort[2]), Convert.ToDouble(tempviewPort[3]));<br />
<br />
Image img = new Image(); <br />
img.Source = bitmapImage; <br />
img.Stretch = Stretch.Fill;<br />
<br />
//Set Image Height (1st Image Height + 2nd Image Height) and Change Left and Top<br />
img.Height = viewport.Height + Convert.ToDouble(vp[3]);  <br />
img.SetValue(Canvas.LeftProperty, Convert.ToDouble(vp[0])); <br />
img.SetValue(Canvas.TopProperty, Convert.ToDouble(vp[1])); <br />
          <br />
//Get Parent element of this image<br />
var parent = path.Parent as Canvas;<br />
//Get index of Image element<br />
var index = parent.Children.IndexOf(path);<br />
parent.Children.Insert(index, img);<br />
<br />
//Microsoft has provided support in Silverlight 4, <br />
//Glyphs has a property of FontSource by which we can assign any font file stream to that. <br />
//By this provision I was able to provide font files to XPS Viewer, <br />
//this saved any extra DLL to be downloaded separately.<br />
    <br />
//Get Font file stream from xps<br />
var stream = Application.GetResourceStream(_streamResourceInfo, ConvertPartName(glyphs.FontUri.ToString())).Stream;<br />
glyphs.FontSource = new FontSource(stream); //assign stream <br />


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


About the Author

Software Developer (Senior) Softech World Wide
Pakistan Pakistan
Rich Media Platform is a collection of technologies that combine to provide an end-to-end solution for interactive-media delivery over the Internet or the Enterprise Network. Each piece of the solution provides value within its own context and can be used de-coupled to do so in a different scenario. For example, Content Caching and Delivery can be used by itself to enhance an existing Video delivery network in an Enterprise, without needing other pieces of the Rich Media Platform.

The following illustration depicts the context for these technologies within a typical system context. Hover your mouse over the links to view brief descriptions.

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171207.1 | Last Updated 4 May 2010
Article Copyright 2010 by AzharTheGreat
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid