click tracking
Katrien's MSDN Blog - Site Home - MSDN Blogs
  • Katrien's MSDN Blog

    My first TechReady experience


    I’m writing this as I’m flying home from Seattle to Brussels via Amsterdam. Feeling a bit cramped here as the person in front of me just put het seat back. But well, that’s with flights right. I have just enough space to open up my laptop and see the whole of my screen. Open up Live Writer and preparing my post-TechReady post (that does sound funny :-). I can hit Publish button as soon as we land.

    I’m returning home after attending Microsoft’s biggest internal technical conference in Seattle. Having joined last year I now got the chance to attend this 5 day, 800+ sessions event with topics for every techie’s need. It’s called TechReady, this is the 7th edition so we tend to call it TechReady7 or abbreviate to TR7.

    Although I’ve been to TechEd events before but this event does feel different, we are all part of the company and because it is held close to campus in Redmond we have the chance to see a lot more of the guys (and some girls) of the product teams. Since this is also an internal event the type of information that we get is looking ahead to the coming months, and did we get to see some very nice stuff! I wish I could write about some of it. PDC will be the time when much of it is announced publicly.

    Topics and sessions
    Without mentioning any details of future releases, I can however divulge the type of sessions I went to. We got to see and learn about the trend the company is taking is regards to software development. To give you an idea, some of the topics are these:

    • Roadmap information on the new version of Visual Studio and .NET
    • Live platform (Virtual Earth, Live APIs), new protocols
    • Live Mesh
    • Software + Services
    • and much more, not so future looking like .NET 3.5 SP1, WPF, ASP.NET, MVC, SharePoint…

    And not to forget a totally crazy session named Mobility Smackdown; If you want to get an idea of the excitement around this session check out a video made last time…

    Special sessions
    As part of DPE, Developer & Platform Evangelism, we had the chance to see Scott Guthrie and Anders Hejlsberg for two Q&A sessions. It was fascinating to have a chance to meet people that I have been looking up to since a long time.

    And not to forget the top speakers we got at the keynotes: Ray Ozzie, Norm Judah, Kevin Turner and producer John Landau speaking about the new Avatar movie.

    TechReady was also an opportunity to meet some of my peers from over the world: Marc (he has an original domain name :), Quixing, Mitsu, Paolo, Mike, Jorge, and so many others!

    Seattle is an international hub during this week, or that’ what the sales guy at the sports store told me.

    Oh, is it true that it always rains in Seattle? The event was held last week, this is the middle of Summer, but we did manage to get rain a few times. So I guess it is true after all…

    TechReady7 logo at the Convention Center in Seattle.

    100_0533 View from the Space Needle onto Seattle downtown.


    Technorati Tags: ,,
  • Katrien's MSDN Blog

    Composite Application Guidance for WPF (previously PRISM)


    The Patterns & Practices team at Microsoft released the Composite Application Guidance for WPF earlier this month. As I blogged about earlier, composite WPF which was code named “Prism” previously, provides guidance in building composite WPF applications.

    When you download the package you get a whole bunch of material:

    • A sample reference application: Stock Trader Reference Implementation
      I always appreciate when samples applications are delivered with the download. This helps me so much better understand and see an example of something that is already working. Normally by looking at how the sample is implemented I get better ideas on how to implement my own project.
    • Composite Application Library for WPF
    • Documentation (300 pages documentation): Composite Baseline Architecture, How-to guides, Stock Trader RI overview, UI Designer Guidance, Design and Technical Concepts and more
    • Quickstarts

    With this release, two main challenges are addressed:

    • Modularity: The Composite Application Library promotes modularity by allowing you to implement business logic, visual components, infrastructure components, presenter or controller components, and any other objects the application requires, in separate modules. Developers can easily create the UI and implement business logic independently of each other.
    • User Interface Composition: The Composite Application Library promotes user interface composition by allowing you to implement visual components from various loosely coupled visual components, known as views, which may reside in separate modules. The visual components may display content from multiple back-end systems. To the user, it appears as one seamless application.

    Here are the main links you need to get started:

  • Katrien's MSDN Blog

    Community Day 2008 – 12 sessions by 9 user groups


    Yesterday the second Belgian Community Day took place in Keerbergen. I joined in a bit later due to some meetings at the office but it was still more than worth it. Nine Belgian User Groups joined in this year to organize a day “For the Community, By the Community”. I would like to thank all the people involved into getting this organized, I know it was a lot of work these last months. Special thanks to Ilse and Gill as they really made sure eveything was running.

    When I got there, halfway during the event, 4 sessions were underway. I decided to join in Riemer Grootjans’ session on XNA game development. It was a great session going over the most important elements to start doing game development. Not (yet) having done any game development myself I was amazed to learn how everything built in 3D is done by drawing triangles! Check out Riemer’s fantastic tutorials Riemer has on his website. This will get you started in no time.

    image  image

    What’s more, Riemer is releasing his first book on XNA development on the 30th of June 2008 and showed us lots of samples from the book. The book is titled “XNA 2.0 Game Programming Recipes: A Problem-Solution Approach” and is being released by Apress.

    Congratulations on this Riemer, I’m going to get one as soon as possible!

    If you want to join other game developers or just game lovers in Belgium, be sure to keep an eye on the new XNA User Group (XNABUG) meetings.

    After Riemer’s session I actually tried to check out more than one session so I saw some new stuff on SQL Server 2008, a debate between Joris and Ilse on Exchange Public Folders and Sharepoit (can’t wait to see the full video of that one :-), and Gill’s Deep Dive on Silverlight 2. Several sessions were recorded so you can expect them online on Chopsticks anytime soon.
    I’m sorry I missed out Kurt Claeys’ session on ADO.NET Entity Framework, I heard it was very good.

    It was nice talking to all of you during dinner. Great work and already looking forward with next year. I hear you have some new ideas…

  • Katrien's MSDN Blog

    New screencasts by Gregory Renard on Chopsticks


    There are now 3 new recordings available on Chopsticks by our Regional Director Gregory Renard.

    The recordings are all on new features of Visual Basic 2008, are available in French and follow the series “10 minutes avec votre RD” that Gregory launched earlier this year.


  • Katrien's MSDN Blog

    MSDN event recording: Using Team Foundation Server for Version Control: Best Practices for TFS Branching and Merging


    Last Wednesday Yves Goeleven presented the MSDN evening session on Team Foundation Server branching and merging patterns. During the introduction Yves explains the main groups of problems that you encounter in the development environment, and how to identify the needs in to your own specific case. Depending on the needs you will lean towards one of the other patterns that is presented during the session.

    Yves has 10 different scenarios for branching and merging practices: going from least complex to the more complex setup and teams (team sizes up to 1000). Every scenario comes with a demo so it gives you a practical example.
    The recording has been split up in three smaller parts (total is 2 hours):

    The powerpoint presentation can be found on Yves’ blog.


    Thanks Yves for the great presentation, and Tom for putting the recordings online so quickly.

  • Katrien's MSDN Blog

    MSDN Evening "Building setup packages with WiX": recording online


    The MSDN evening session from last week has been recorded and can be watched online on our Chopsticks platform. In this session, Martijn Beenes, coming specially from the Netherlands for this session, explains how to use the installer tools, MSI's, WiX toolset (Windows Installer XML), and shows how to create a fully customized Windows installer packages using WiX.

    View the session online: (you will need to login for this as it's premium content).

    Together with the recording you can also find the PowerPoint presentation by clicking the Resources tab.

    Martijn, thanks for the great session, we hope to see you again in Belgium in the future.


    Tags van Technorati: ,,
  • Katrien's MSDN Blog

    Silverlight 2 Beta 2 and related downloads


    During the opening keynote at TechEd Orlando last Tuesday, Soma announced the availability of Silverlight 2 Beta 2. As from now you can find the different downloads related to Silverlight 2 Beta 2. The best place to start is reading Scott Guthrie's post on the beta 2 release. As always, he gives a clear overview of what is new with some very interesting samples.

    Links to main Silverlight 2 Beta 2 downloads

    New and improved features

    Go live license: there is now a commercial Go-live license for Silverlight 2 Beta 2. Hey, if NBC is going live on this version for the Olympics why shouldn't you?

    Data: LINQ-to-JSON, ADO.NET Data Services support (Astoria) and other enhancements to make data handling easier. theADOGuy has a good post on Silverlight 2 and Astoria.

    Networking: I'm glad there is now support for duplex communications (“push” from server to Silverlight client, yes, yes, yes! this one was a much requested feature), improved cross domain support and security enhancements and upload support for WebClient.

    Rich controls: TabControl (new in Beta 2, check out Tim's post on this), wrapping and scrolling for the TextControl, and a new templating model called Visual State Manager (VSM) that allows for easier templating for controls. Check Christian Schormann's post for an introduction to VSM.

    Deep zoom: there is now an XML-based file format for Deep Zoom image tiles, as well as a new MultiScaleTileSource that enables existing tile databases to utilize Deep Zoom. This means you will have to re-generate your Deep Zoom projects and adapt some of the code in the Silverlight implementation.

    If you are interested in reading about other announcements that were made during the TechEd keynote, Gill has some details.

  • Katrien's MSDN Blog

    Prism: codename for the new guidance for Composite Application development for WPF


    imagePrism is the codename for the new guidance for Composite Application development for WPF. This is not an update to CAB (Composite UI Application Block), it delivers a new set of assets and guidance for developing new Composite WPF applications. As it is not based on previous smart client offerings it is really optimized for WPF and gives a simplified approach that is more easily adoptable. Prism includes a reference implementation, reusable library code and pattern guidance.

    I've been reading on Prism and collected a few URLs that should get you started on Prism. Please note that this is still not in beta, drop 6 is currently available for download from the CodePlex site.

    If you are wondering whether Prism is a replacement for Acropolis (which has been delayed), it's not really the same thing. Acropolis is still undergoing and will be folded into future versions of the .NET platform. "Prism" focuses only on a subset of what Acropolis was aiming to provide.

    There is one thing I don't like though, hope the team comes up with a nicer logo :-) sorry guys, really not my thing.

  • Katrien's MSDN Blog

    VSX, VISUG and Multi-mania events


    I'm really running behind with my blogging, these have been busy weeks. I was at several community events and did a presentation at Multi-mania. Wow, that was a first where everybody was talking around mostly non-Microsoft products. Gill, Brecht and I were the only ones doing sessions on Microsoft technologies. The good thing to see there was the openness of the audience. Lots of people talking about Silverlight, curiosity to say the least.

    VISUG event on VSX

    On Tuesday 20th of Mary we had the visit of James Lau and Jean-Marc Prieur from the VSX team (Visual Studio Extensibility). They are on tour through Europe and did a first presentation at Microsoft offices, in the evening there was a VISUG user group event foreseen.
    James and Jean-Marc did a wonderful session on Visual Studio Extensibility: extension packages, DSL tools, entDev, etc. The good news is my colleague Tom already did all the encoding of the recorded videos and you can view the whole session online. If you want to learn more about extending Visual Studio, using the Visual Studio Shell for host your own designers and programming environment and more: check out the videos.
    During the presentation Jean-Marc did two full demos of building tools from scratch: building a custom source code outliner and building a custom DSL. This is a great way to get started on your own. Also check out James' write-up about the day.

    Here is a list of resources that are worth checking out around VSX:

    Wygday and BIWUG event

    The Belgian Information Worker User Group meeting was last Thursday. I had a lot of trouble to get there on time...
    In the morning I travelled to Lille (boy, that's no longer Belgium, that's France!) to attend the Wygday, an event organized by Wygwam, the company of our Regional Director Gregory Renard. There were lots of interesting sessions around SharePoint, Silverlight, .NET Framework 3.5 SP1, GAT, GAX, etc. The event was organized together with Microsoft France but as quite some Belgian developers go over there as well it was worth the travel to meet up.

    Then I left early enough to get to the BIWUG meeting in Kontich but had the bad luck of getting stuck in two big traffic jams. Result: a 1h30 drive took more than 3h30. But I still got to the BIWUG event, even if I was late!

    When I arrived there the first presentation was already well under way: an introduction to Lotus software (Quickr), only got to see the final part of this presentation.
    Then Kurt Claeys did a presentation on Bizatlk integration with SharePoint Services and MOSS. Donwload his and the other presentation slides from Joris' blog.

    Multi-mania event in Kortrijk

    As I already mentioned in the beginning of this post, Friday 23rd May was Multi-mania day. It was a first for me to be presenting at a non (MS) developer event, lots of creative people around with presentations about their work, vision of the future of the web and lots of interactive and design technology (can you guess who was the main sponsor? :-).
    Gill did a general RIA development with Silverlight 2 session. As always, I think it was very well structured and introduces the technology well for people not having done Silverlight yet. The room was not completely full but the audience was very interested in seeing what Microsoft is doing in that space.

    Brecht, one of the founders of the new XNA user group in Belgium (XNABUG) did a presentation on XNA game development, he had some great samples with games on a Zune and some of the projects Belgian participants of the Imagine Cup. That same day we actually got the good news that one of the Belgian teams has made it to the final 6 in Game Development in the Imagine Cup. Congratulations guys!

    My own session was focused on the learning's for designers when doing WPF and Silverlight projects in Expression Blend. I mostly used great samples provided by Arturo Toledo, a designer audience product manager at Microsoft. He did a fantastic session at MIX that you definitely need to check out: XAML Ready Agency with Expression Blend.

    VISUG HHH session: Introduction to Workflow Foundation

    This week another VISUG event took place at Ordina in Merelbeke, presented by Kurt Claeys. Kurt again, he is keeping busy! Kurt gave a good overview of what Workflow Foundation is all about with lots of samples. He started by explaining the basics using .NET 3.0 samples and then moved to version 3.5, explaining the main updates between the two releases. 

    I especially appreciated the TV sample he made to explain State Machine workflows. This is actually explained in an article he did 2 years ago: State Machine Workflows in Windows Workflow Foundation. This is still version 3.0 but very usable in the current version as the article explains the concepts.

    Kurt is already in Orlando for next week's TechEd US, where he will be helping out with the Hands-on-Labs the whole week. Have a nice time Kurt!

    Workflow Foundation: new articles by Serge Luca

    And to finish off, Serge Luca has posted part 11 and 12 of his Step by Step Tutorial "Creating Workflows for Windows Sharepoint Services and MOSS2007". Check out the two new articles on his blog:

  • Katrien's MSDN Blog

    Watch VISUG session on VSX (Visual Studio Extensibility) online


    Last week James Lau and Jean-Marc Prieur from the Visual Studio Extensibility team, visited Belgium and did a presentation at VISUG user group. If you missed the session or have not yet seen much about VSX this is a good opportunity. It's a 2 hour presentation with lots of demos.

    You can now watch the whole presentation online, it has been split into 5 parts:

  • Katrien's MSDN Blog

    Next BIWUG meeting Thursday 22nd May 2008


    The next meeting for the Belgian Information Worker User Group is taking place on May 22nd 2008 at 19:00.

    During this meeting there are three sessions planned:

    • Biztalk integration with SharePoint and InfoPath forms using the Biztalk 2006 R2 SharePoint adapter by Kurt Claeys
    • IBM Team Collaboration Software – Lotus software by Koen Renders en Tom Van Aken
    • Windows Workflow Foundation – deep dive by Tom Nys

    You can read more details on the BIWUG site and register for the event here, it's always a great opportunity to learn something new and meet with peers.

  • Katrien's MSDN Blog

    .NET 3.5 SP1 Beta and Visual Studio 2008 SP1 Beta are out


    Today we released the Beta versions of the Service Packs that will be shipping for .NET 3.5 and Visual Studio 2008.

    Please note that the betas are intended as a mechanism to allow early testing and feedback. As a beta release, it is recommended that you only install the service pack on test machines.

    What is new with these Service Packs?

    There are several bug fixes and enhancements, the most notable ones I'm listing in here.

    • WPF enhancements: more controls, a streamlined setup, improved start-up performance, and powerful new graphics features. See Channel9 post for more details.
    • .NET Framework Client release ("Arrowhead"): this is subset of the full .NET Framework 3.5 SP1. It allows for faster setup on client machines not yet running version 3.5 of the .NET framework. This new setup installer enables a faster, simpler installation experience for .NET applications on Windows XP and Windows Vista.
    • ASP.NET Dynamic Data
    • ADO.NET Entity Framework
    • ADO.NET Data Services (codename "Astoria")
    • The .NET Framework Data Provider for SQL Server (SqlClient) adds new support for file stream and sparse column capabilities in SQL Server 2008.

    Update: Review the complete, extensive, detailed list of enhancements on ScottGu's blog. As always, Scott's post gives you all possible information you need on this.

    Compatibility issues with Silverlight 2 Beta 1 tools

    Note that there are a few known incompatibilities with this service pack including: Expression Blend, the Silverlight 2 Beta 1 SDK, and the Microsoft Silverlight Tools Beta 1 for Visual Studio 2008. A new version of Expression Blend 2.5 March Preview has been released here that is compatible with this service pack. 

    Technorati Tags: ,
  • Katrien's MSDN Blog

    Silverlight collaboration demo source code from the MIX essentials keynote


    A few people at the MIX essentials event we organized in April requested me to post the source code for the Silverlight demo we gave in the opening keynote. So, here is the code (download at the bottom) along with some explanations of what we implemented. What's also available: a running example hosted at Silverlight Streaming.


    Check out the recording of the session to view the demo being demonstrated live.

    Button style

    The "Refresh" button's style is customized by using Application Resources. Application resources allow you to define styles and templates to be applied to controls. Check out this tutorial on styles and templates in Silverlight.

    Style and templating defined in App.xaml file:

            <!-- Button -->
            <Style x:Key="hardComic" TargetType="Button">
                <Setter Property="IsEnabled" Value="true" />
                <Setter Property="IsTabStop" Value="true" />
                <Setter Property="Foreground" Value="#FFFFFFFF" />
                <Setter Property="FontSize" Value="16" />
                <Setter Property="Cursor" Value="Hand" />
                <Setter Property="TextAlignment" Value="Center" />
                <Setter Property="TextWrapping" Value="NoWrap" />
    <!-- code omitted -->

    The custom style is applied to the button by using the key (Page.xaml file):

    <Button x:Name="buttonRefresh" Style="{StaticResource hardComic}" ... />

    By applying a custom style and control template, the layout of the button changes from




    Bubble animation

    The bubbles in the test tube were created in Expression Blend 2.5. The animation is created by moving the bubbles from the bottom of the test tube to the limit of the pink liquid. This is done in a Storyboard containing several keyframes for the different bubbles. A different path is used for each bubble so that the effect is like real bubbles are coming up. At the end of the storyboard, Opacity of each bubble is set to 0% so that these are no longer visible. We also set the Repeat behavior of the storyboard to Forever so that the animation keeps on playing once its started.

    image  (click to enlarge)

    Thanks to Stijn for the animation!

    Loading images through REST

    Photos are loaded by accessing the Flickr search REST service. This is done by creating a WebClient object, accessing the service asynchronously and then parsing the returned XML to load the photos on the surface:

    private void LoadPictures()
                // Initialize Flickr URI
                string tags = "mixessentialsbe";
                string key = "hidden";
                string flickrApi = string.Format("
    , key, tags); // Asynchronous call to REST Service WebClient rest = new WebClient(); rest.DownloadStringCompleted += new DownloadStringCompletedEventHandler
    (rest_DownloadStringCompleted); rest.DownloadStringAsync(new Uri(flickrApi)); } void rest_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { if (!_photosLoaded && (0 != Width) && (0 != Height)) { //... some code omitted if (doc.Element("rsp").Attribute("stat").Value == "ok") { // Current Page Logic int totalPages = Convert.ToInt32(doc.Descendants("photos").Single().
    Attribute("total").Value); if (_pageIndex >= totalPages) _pageIndex = 0; // Get Photo collection using Linq to XML var photos = (from results in doc.Descendants("photo") select new { id = results.Attribute("id").Value.ToString(), farm = results.Attribute("farm").Value.ToString(), server = results.Attribute("server").Value.ToString(), secret = results.Attribute("secret").Value.ToString() }).Skip(_pageIndex * 10).Take(10); // Add a photo control for each Photo returned foreach (var photo in photos) { url = string.Format("http://farm{0}{1}/{2}_{3}_m.jpg",, photo.server,, photo.secret); new Photo(this, this.SurfaceLayoutRoot, new Uri(url)); } _photosLoaded = true; } } }

    I recommend reading Gill's tutorial on Silverlight 2 data and services for detailed information on accessing services using Silverlight.

    The Surface-like experience

    To show the photos we reused some sample code from the Community samples at Silverilght Surface sample.

    This example includes a custom Photo class that we have reused and slity adapted to fit the new parent object (our Page.xaml). It adds a really cool experience to displaying the photos.


    Getting the source code to work: Flickr API key

    You do need to request your own API key at Flickr and add it to the code before being able to run the code locally. Sign-up for a key at the Flickr site and then change the key in Page.xaml.cs file:

     private void LoadPictures()
                // Initialize Flickr URI
                string tags = "mixessentialsbe";
                //todo: create your own API key at Flickr and copy here:
                string key = "flickr api key here";
                string flickrApi = string.Format("{0}&tags={1}", key, tags);
            //rest of code omitted...     

    Add the key, rebuild and the app should run locally.

    Download the source code

    Code can be downloaded from my Skydrive.

  • Katrien's MSDN Blog

    MIX essentials 2008 Roundup


    IMG_1376Last week on April 24th we had our first MIX essentials event in Belgium. It was a full day with a dynamic opening keynote; developer and designer break-out sessions and of course a fantastic closing keynote and Q&A session with Steve Ballmer.

    Opening keynote

    The opening keynote was a mix of presentations, demos and some cool videos (if I say so myself :-)). Luc van de Velde was the conductor doing the intro of the developer/designer collaboration story and orchestrating all demos and other presenters. clip_image001
    The first demo was done by 4 guys from 4 of Belgium's top web agencies, each of them with a defined role in the collaboration story: Jan from Nascom, Stijn from These Days, Thomas from LBi and Chris from Emakina. Check it out here.

    Next we had Martin Tirion, UX Evangelist coming over from the Netherlands to present us the newest around IE8, Silverlight 2 and Expression Suite 2. I did a few demos during his part as well.

    To close off the keynote, Catherine Heller, Technical Evangelist came over from Redmond for an overview of the Windows Live platform. She also invited someone from Truvo on stage to give a demo on their Live Agent to search for phone numbers of people and businesses. If you want to add the bot to your messenger account just add a friend and choose for French or for Dutch.


    Recordings of all sessions

    All sessions are now (yes now!) available on our MSDN Chopsticks platform, keynote videos are available without login, for the breakout sessions simply login using a Live ID account as this is premium content. The PowerPoint presentations are also available for download with each video.


    Designer sessions were delivered by David Pugh-Jones, Ian Griffiths and Paul Dawson. Developer sessions were delivered by Tim Heuer, Catherine Heller and Gill Cleeren.

    Pictures of the event

    Lots of pictures have been posted on Flickr (thanks Miel and Gill).

    IMG_1317 IMG_1333 

    What's next?

    Hopefully next year we will be hosting a second edition of MIX essentials and we'll see you there. In the meantime, subscribe to our newsletter Express Yourself, keep track of the news on our Twitter account and Light up the web!

    Here are some resources mentioned during the event to get you started on Silverlight and Microsoft Expression.

  • Katrien's MSDN Blog

    Different ways for loading images and files in Silverlight 2 applications


    When loading files in Silverlight 2 applications, this can range from images, video, fonts, etc, there are several options available. You might want to call files that reside on another server, files that are embedded into the .xap application or zip files that are downloaded and unpackaged on the client. In this post I’m reviewing the different options available for this, differences between them and how to implement each of the options.

    As an example to load the files I’m using a UserControl with an image on it. A very simple example that is clear enough to show the different approaches. All of the examples I'm showing here have a XAML based approach with a code based counterpart, except for the sample for on demand download.

    Base UserControl

    <UserControl x:Class="SLLoadResourcesApproaches.Page"
        <Grid x:Name="LayoutRoot" Background="White">
            <Image x:Name="imageElement" Stretch="Uniform" />

    This just displays the image, nothing more:


    Referencing files in the same directory as the Silverlight application (ClientBin directory )

    In other words, this is the default location of your .xap file, so files that are located in the same directory as the base application. By default when you create the Silverlight application with a test web site in Visual Studio this is the ClientBin directory. No extra code is needed to load files in this location.

    If the file is placed in the ClientBin directory, call the file in XAML:

    <Image x:Name="imageElement" Stretch="Uniform" Source="_DTH8643.jpg" />

    Or in code:

    imageElement.Source = new BitmapImage(new Uri("_DTH8643.jpg", UriKind.Relative));

    Note: for the above sample you can use a forward-slash preceding the image name to express that it is located relative to the .xap file (same directory in this case). This is important to not as here it is not the root of the domain name (absolute path) that is taken into account. Take this example where I have a sub-directory to ClientBin, I’m referencing the file as /images/imagename.jpg.


    To reference the file in the images directory in the ClientBin:

    imageElement.Source = new BitmapImage(new 
    Uri("/images/_DTH8643.jpg", UriKind.Relative));

    First time I used this it caused some confusion as I'm used to referrring to files in the root of the domain in this way, not in a sub-directory, so it's important to note this difference with Silverlight.

    Copying files to ClientBin upon build in Visual Studio

    In the case you are using the files directly in your Silverlight application and don't want to copy them manually to the ClientBin directory you can set this in Visual Studio. Note this is a copy to the ClientBin directory of the Silverlight application project, not the test web project you may have created.
    Build action: None.
    Copy to Output Directory: Copy always.


    Loading files located outside of ClientBin (.xap location) directory

    In the above screenshot I have an image files located in the "images2" directory. To load images from that directory I can enter the full URL of the image:

    <Image x:Name="imageElement" Stretch="Uniform" 

    In C# code:

    imageElement.Source = new BitmapImage(
    new Uri("http://localhost:55907/SLLoadResourcesApproaches_Web
    , UriKind.Absolute));

    Referencing files on external web sites

    If you want to call images that reside on external sites you can use the standard download method by using WebClient. Remember that cross domain restrictions apply.
    Other than that it is just like calling images using the full URL like above.

    imageElement.Source = new BitmapImage(new 
    Uri("", UriKind.Absolute));

    There is however maybe a better way to load a file in from an external site where you can better control the loading of your file before showing it in the UI. By using the WebClient class you can download external files on demand, be it from the current origin site or external sites (see below notes on cross domain restrictions). Using the WebClient you can control what to display while the image or file is being downloaded using event handlers. This approach however is not available in XAML but only in code.

    1. Create a WebClient object, an OpenReadCompleted event handler and start the download process

    WebClient webClientImgDownloader = new WebClient();
    webClientImgDownloader.OpenReadCompleted += new 
    OpenReadCompletedEventHandler(webClientImgDownloader_OpenReadCompleted); webClientImgDownloader.OpenReadAsync(photo);

    2. Set the source to the image in the OpenReadCompleted event handler

     void webClientImgDownloader_OpenReadCompleted(object sender, 
    OpenReadCompletedEventArgs e) { BitmapImage bitmap = new BitmapImage(); bitmap.SetSource(e.Result); imageElement.Source = bitmap; }

    Referencing files included in application package (the .xap file, not the assembly)

    When you need your Silverlight application to be independent of any files stored on the server separately you can include everything into a single .xap file. The same applies to file that are integral part of the application. If you know a certain file is always used when running the application it makes sense to include it in the .xap file as there is no reason to download it separately. Including files to be part of the package is what we call Content files.

    Files that are packaged into the .xap file need to have the Build Action in Visual Studio set to "Content".


    To call the file from XAML:

    <Image x:Name="imageElement" Stretch="Uniform" Source="/_DTH8643.jpg" />

    Calling from code:

    imageElement.Source = new BitmapImage(new Uri("/_DTH8643.jpg", UriKind.Relative));

    Because the files is located at the same level in the application package as the assembly in which the code is running, the forward-slash preceding the name is required here as well.

    Files can also be located in sub-directories of the application package. You will notice that the directories are also included in the .xap file (as they would in any .zip archive file).

    Application resources: calling files embedded in the application assembly (DLL)

    As with other .NET assemblies, files can be embedded into the assembly as resources. For Silverlight applications, set the file Build Action to Resource.


    Referencing resources embedded into the assembly is implemented in the same way as loading files included in the application (.xap). The difference is they are added to the DLL and thus no longer visible in the .xap file if you unzip it. 

    In XAML:

    <Image x:Name="imageElement" Stretch="Uniform" 
    Source="/_DTH8643.jpg" />

    Code call:

    imageElement.Source = new BitmapImage(new 
    Uri("/_DTH8643.jpg", UriKind.Relative));

    This is working well for the current assembly but if you want to use a file located in a referenced assembly (a Silverlight class library) you will need to add a special reference to indicate the assembly you are calling the file from. This is done by adding the following prefix to calling the file:

    So, in the example below I'm calling an image from the assembly named ReferencedSlLibrary.

    <Image x:Name="imageElement" Stretch="Uniform" 
    Source="/ReferencedSlLibrary;component/_DTH8643.jpg" />

    Code call:

    imageElement.Source = new BitmapImage(new 
    Uri("/ReferencedSlLibrarys;component/_DTH8643.jpg", UriKind.Relative));

    VS 2008 - SL 2 Beta 1 note: you will notice that the image does almost only get displayed in the Visual Studio designer if you set the source in the above manner, even for own assembly files. I'm guessing this is a bug in beta 1.

    Embedding fonts

    To embed fonts there is actually a specific implementation to call upon font files, see this great post by Tim Heuer on the different ways to do this.

Page 24 of 27 (400 items) «2223242526»