<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>This blog is dead, long live this blog</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/lgmorand/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/lgmorand/feed.xml</link>
    <description>by Louis-Guillaume Morand</description>
    <lastBuildDate>Tue, 16 Apr 2019 05:16:09 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Windows 8 - Développement d’une application Metro localisée</title>
      <link>https://docs.microsoft.com/archive/blogs/lgmorand/windows-8-dveloppement-dune-application-metro-localise</link>
      <pubDate>Sat, 12 May 2012 14:38:00 GMT</pubDate>
      <dc:creator><![CDATA[Louis-Guillaume Morand]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/lgmorand/2012/05/12/windows-8-dveloppement-dune-application-metro-localise/</guid>
      <description><![CDATA[Windows 8 dont&#160; la sortie est normalement prévue pour le second semestre (aucune date confirmée...]]></description>
      <content:encoded><![CDATA[<p>Windows 8 dont&#160; la sortie est normalement prévue pour le second semestre (aucune date confirmée pour le moment) prend peu à peu sa place dans le viseur des DSI et le nombre de projets Windows 8 ne cesse de croitre. Parmi les besoins communs aux différentes applications, c’est très souvent le besoin d’une version localisée qui se fait ressentir. Ce sujet, qui peut paraitre simple nous a laissé quelques surprises au fil des versions bêta de Windows 8.</p>  <h1>Localisation d’une application XAML</h1>  <p>Il existe de très nombreuses façons de localiser une application, que ce soit pas le code-behind ou même le XAML et il n’est pas nécessaire ici de refaire une passe sur toutes ces solutions. je vais parler ici de la plus simple et bien souvent la plus propre car elle simplifie le code au maximum mais elle demande de la rigueur notamment dans la maintenance du fichier de ressource et spécifiquement sur le nom des clés. Voyons pourquoi.</p>  <p>La solution la plus simple de localiser votre application est de définir l’attribut <strong>x:Uid</strong> sur tous les éléments que vous souhaitez localiser. Que ce soit un bouton, un textblock ou tout autre élément, votre objet peut avoir cet attribut et celui-ci va correspondre à la clé du fichier de ressource pour retourner une chaine de caractère spécifique.</p>  <p>Pour se faire commencez par ajouter un fichier de ressource à votre projet (<em>Ajouter &gt; nouveau élément &gt; Fichier de ressource</em>)</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/0825.loc1_03DBB1DB.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/0825.loc1_5F00_03DBB1DB.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="loc1" border="0" alt="loc1" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/5826.loc1_thumb_1EA7D7E7.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/5826.loc1_5F00_thumb_5F00_1EA7D7E7.png" width="264" height="95" /></a></p>  <p>&#160;</p>  <p>Puis dans ce fichier, ajoutez vos clés et la chaine traduite puis notez la spécificité des clés de la capture suivante :</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/4428.loc2_0152801D.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/4428.loc2_5F00_0152801D.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="loc2" border="0" alt="loc2" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/5187.loc2_thumb_545D1D41.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/5187.loc2_5F00_thumb_5F00_545D1D41.png" width="415" height="112" /></a></p>  <p>Vous remarquerez que ertaines clés finissent par .Text. C’est par ce suffixe que le moteur XAML va savoir, grâce à l’attribut x:Uid, aller chercher la clé puis utiliser le suffixe pour déterminer l’attribut de l’élément à localiser. Pour être plus clair, pour localiser le texte d’un label et d’un bouton comme ci-dessous</p>  <pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">TextBlock</span> <span class="attr">x:Uid</span>=”<span class="attr">Cle1</span>” <span class="kwrd">/&gt;</span>

<span class="kwrd">&lt;</span><span class="html">Button</span> <span class="attr">x:Uid</span>=”<span class="attr">Cle2</span>” <span class="kwrd">/&gt;</span></pre>


<p>&#160;</p>

<p>Les clés devront s’appeler</p>

<table border="1" cellspacing="0" cellpadding="2" width="300"><tbody>
    <tr>
      <td valign="top" width="150">Cle1.Text</td>

      <td valign="top" width="150">Texte de mon label</td>
    </tr>

    <tr>
      <td valign="top" width="150">Cle2.Content</td>

      <td valign="top" width="150">Texte de mon bouton</td>
    </tr>
  </tbody></table>

<p>Il est ainsi permis de localiser n’importe quel attribut d’un élément XAML. Par contre, cela demande une bonne organisation du fichier de ressource car si un label est utilisé à la fois sur un bouton et un label, du fait que l’attribut visé sera différent, le nom de la clé aussi et finalement l’information devra être dupliquée.</p>

<p>&#160;</p>

<h2>Le cas particulier de l’application bar</h2>

<p>L’application bar est un cas particulier et je n’aurai personnellement jamais trouvé la solution sans notre évangéliste de choc <a href="http://blogs.msdn.com/b/eternalcoding/" target="_blank">David Catuhe</a>. Voici les détails.</p>

<p>Un bouton d’AppBar XAML Metro ressemble au code suivant :</p>

<pre class="csharpcode">&lt;Button x:Name=<span class="str">&quot;Add&quot;</span> Style=<span class="str">&quot;{StaticResource AddAppBarButtonStyle}&quot;</span> &gt;</pre>

<pre class="csharpcode">&#160;</pre>


<p>Avec un style qui redéfinit les propriétés d’automation pour définir le label du bouton (Automation.Name)</p>

<pre class="csharpcode">&lt;UserControl.Resources&gt;
...
    &lt;Style x:Key=<span class="str">&quot;WebViewAppBarButtonStyle&quot;</span> TargetType=<span class="str">&quot;Button&quot;</span> 
           BasedOn=<span class="str">&quot;{StaticResource AppBarButtonStyle}&quot;</span>&gt;
        &lt;Setter Property=<span class="str">&quot;AutomationProperties.Name&quot;</span> Value=<span class="str">&quot;Votre texte&quot;</span>/&gt;
        &lt;Setter Property=<span class="str">&quot;Content&quot;</span> Value=<span class="str">&quot;&amp;#xE12B;&quot;</span>/&gt;
    &lt;/Style&gt;
&lt;/UserControl.Resources&gt;</pre>


<p>&#160;</p>

<p>Sauf que, comme expliqué plus haut le mécanisme de localisation se base sur le nom de la clé, ce qui donnerait dans notre cas NotreCle.Automation.Name et là... c’est le drame. En effet, le moteur XAML n’apprécie pas du tout d’avoir deux fois un “.” dans la clé car il ne sait pas s’il doit chercher un attribut Name ou un attribut Automation.Name. Nous sommes bloqués.</p>

<p>Du fait des mécanismes internes concernant les propriétés d’automation notamment que le fait que la valeur de Automation.Name <a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.ui.xaml.automation.automationproperties.name" target="_blank">est automatiquement prise depuis la valeur de la propriété Content</a>, il peut être tentant de passer par cette propriété mais dans ce cas, impossible d’utiliser la propriété Content pour afficher une image grâce à la police Segoe UI par exemple.&#160; Encore bloqués.</p>

<p>La solution de se passer complètement d’un label n’étant pas une solution viable, il me fallait trouver autre chose tout en restant au maximum dans la mentalité du full XAML (sans code-behind). La solution se trouve simplement dans une syntaxe non documentée qui permet de localiser un champ non accessible normalement :</p>

<pre class="csharpcode">VotreCle.[<span class="kwrd">using</span>:Windows.UI.Xaml.Automation]AutomationProperties.Name</pre>

<pre class="csharpcode">&#160;</pre>


<p>Ainsi dans notre cas et notre bouton about, la clé sera “AppBar-General-About.[using:Windows.UI.Xaml.Automation]AutomationProperties.Name” tandis que le XAML ressemblera à ceci</p>

<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">Button</span>  <span class="attr">x:Name</span><span class="kwrd">=&quot;About&quot;</span> 
                <span class="attr">Style</span><span class="kwrd">=&quot;{StaticResource AboutAppBarButtonStyle}&quot;</span> 
                <span class="attr">x:Uid</span><span class="kwrd">=&quot;AppBar-General-About&quot;</span> 
               ...<span class="kwrd">&gt;</span>
 <span class="kwrd">&lt;/</span><span class="html">Button</span><span class="kwrd">&gt;</span></pre>


<p>&#160;</p>

<p>&#160;</p>

<h2>Quid des message box?</h2>

<p>Contrairement aux Winforms où vous étiez obligés d’avoir une partie (notamment les boutons OK, Cancel, Oui, Non, etc.) liés non pas à la langue de votre application mais à celle du système, les applications Metro vont vous permettre de localiser le contenu de ces boutons mais surtout d’en rajouter autant que vous voulez en leur assignant des actions, simplement avec une classe de ce type :</p>

<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">class</span> MessageBox
        {
            <span class="rem">/// &lt;summary&gt;</span>
            <span class="rem">/// Display a error messagebox</span>
            <span class="rem">/// &lt;/summary&gt;</span>
            <span class="rem">/// &lt;param name=&quot;title&quot;&gt;&lt;/param&gt;</span>
            <span class="rem">/// &lt;param name=&quot;message&quot;&gt;&lt;/param&gt;</span>
            <span class="kwrd">public</span> <span class="kwrd">static</span> async Task&lt;<span class="kwrd">bool</span>&gt; Show(<span class="kwrd">string</span> title, <span class="kwrd">string</span> message)
            {
                MessageDialog dialog = <span class="kwrd">new</span> MessageDialog(message, title);
                <span class="kwrd">bool</span> result = <span class="kwrd">false</span>;
                dialog.Commands.Add(
                <span class="kwrd">new</span> UICommand(Localizer.GetKey(<span class="str">&quot;General-OK&quot;</span>), <span class="kwrd">new</span> UICommandInvokedHandler((cmd) =&gt; result = <span class="kwrd">true</span>)));
                dialog.Commands.Add(
                   <span class="kwrd">new</span> UICommand(Localizer.GetKey(<span class="str">&quot;General-Cancel&quot;</span>), <span class="kwrd">new</span> UICommandInvokedHandler((cmd) =&gt; result = <span class="kwrd">false</span>)));
                await dialog.ShowAsync();
                <span class="kwrd">return</span> result;
            }

            <span class="rem">/// &lt;summary&gt;</span>
            <span class="rem">/// Display a error messagebox with additionnal commands</span>
            <span class="rem">/// &lt;/summary&gt;</span>
            <span class="rem">/// &lt;param name=&quot;title&quot;&gt;&lt;/param&gt;</span>
            <span class="rem">/// &lt;param name=&quot;message&quot;&gt;&lt;/param&gt;</span>
            <span class="kwrd">public</span> <span class="kwrd">static</span> async <span class="kwrd">void</span> Show(<span class="kwrd">string</span> title, <span class="kwrd">string</span> message, List&lt;UICommand&gt; commands, <span class="kwrd">int</span> defaultCommandIndex)
            {
                MessageDialog dialog = <span class="kwrd">new</span> MessageDialog(message, title);
                <span class="kwrd">foreach</span> (UICommand comm <span class="kwrd">in</span> commands)
                {
                    dialog.Commands.Add(comm);
                }

                <span class="kwrd">if</span> (defaultCommandIndex &lt;= (commands.Count - 1))
                {
                    dialog.DefaultCommandIndex = (<span class="kwrd">uint</span>) defaultCommandIndex;
                }

                await dialog.ShowAsync();
            }
        }</pre>


<p>&#160;</p>

<p>Ainsi, il vous faudra donc user de ces trois techniques pour localiser complètement votre application mais vous pourrez ainsi permettre à l’utilisateur d’avoir une application complètement traduite dans la langue de son choix, même si son système ne gère pas cette langue.</p>

<p>&#160;</p>

<h1>Et pour le HTML5?</h1>

<p>Et bien pour le HTML5, un mécanisme plus ou moins similaire a été mis en place et il devient très simple de localiser son application.</p>

<p>Je vous encourage également à lire <a href="http://blogs.msdn.com/b/eternalcoding/archive/2012/04/16/comment-cuisiner-une-application-windows-8-avec-html-5-css3-et-javascript-en-une-semaine-jour-2.aspx" target="_blank">l’article très clair de David Catuhe</a> concernant ce sujet ou bien vous inspirer du <a href="http://code.msdn.microsoft.com/windowsapps/Application-resources-and-cd0c6eaa" target="_blank">sample du SDK concernant la localisation</a>.</p>

<p>&#160;</p>

<p>- Louis-Guillaume Morand -</p>]]></content:encoded>
    </item>
    <item>
      <title>Retrouver le menu classique de Windows 7 dans Windows 8</title>
      <link>https://docs.microsoft.com/archive/blogs/lgmorand/retrouver-le-menu-classique-de-windows-7-dans-windows-8</link>
      <pubDate>Thu, 15 Sep 2011 05:00:00 GMT</pubDate>
      <dc:creator><![CDATA[Louis-Guillaume Morand]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/lgmorand/2011/09/15/retrouver-le-menu-classique-de-windows-7-dans-windows-8/</guid>
      <description><![CDATA[Edit : cette feature ne marche plus depuis la RTM
&nbsp;
Hier, Microsoft a mis a disposition une...]]></description>
      <content:encoded><![CDATA[<p><span style="background-color: #ffff00;"><strong>Edit : cette feature ne marche plus depuis la RTM</strong></span></p>
<p>&nbsp;</p>
<p>Hier, Microsoft a mis a disposition une version preview (moins avanc&eacute; qu&rsquo;une beta!) de Windows 8, son futur syst&egrave;me d&rsquo;exploitation. Celui-ci, optimis&eacute; pour les PC et les tablettes, capable de fonctionne sur de nouveaux types de processeurs comme ARM, vient surtout avec une interface graphique enti&egrave;rement revue utilisant le style all&eacute;g&eacute; dit &ldquo;Metro&rdquo; .</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/0385.image_thumb20_7BCA6BF5.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/0385.image_5F00_thumb20_5F00_7BCA6BF5.png"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image_thumb[20]" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/5153.image_thumb20_thumb_7F1BDDD0.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/5153.image_5F00_thumb20_5F00_thumb_5F00_7F1BDDD0.png" alt="image_thumb[20]" width="260" height="208" border="0" /></a></p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/6215.image_thumb22_5C779F55.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/6215.image_5F00_thumb22_5F00_5C779F55.png"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image_thumb[22]" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/7024.image_thumb22_thumb_56F908E4.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/7024.image_5F00_thumb22_5F00_thumb_5F00_56F908E4.png" alt="image_thumb[22]" width="655" height="330" border="0" /></a></p>
<p>Malheureusement, certains r&eacute;tifs au changement (dont moi) voudraient retrouver le menu de Windows 7, si fonctionnel! mais en gardant le menu d&eacute;marrer de Windows 8 avec le panel de Widgets</p>
<p>&nbsp;</p>
<p>Pour le faire, c&rsquo;est assez simple:</p>
<ol>
<li>ouvrer la fen&ecirc;tre de commande (Win + R)</li>
<li>tapez &ldquo;regedit&rdquo;</li>
<li>Allez &agrave; la cl&eacute; <strong>HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer</strong></li>
<li>Changez la valeur de la cl&eacute; <strong>RPEnabled</strong> de 1 &agrave; 0</li>
</ol>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/6013.image_thumb24_1FEF04DE.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/6013.image_5F00_thumb24_5F00_1FEF04DE.png"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image_thumb[24]" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/3326.image_thumb24_thumb_6CEF4EA9.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/3326.image_5F00_thumb24_5F00_thumb_5F00_6CEF4EA9.png" alt="image_thumb[24]" width="726" height="239" border="0" /></a></p>
<p>Le syst&egrave;me prend cela en compte tout de suite, pas besoin de red&eacute;marrer. Pour le faire marcher, il faut cliquer sur la touche Windows une fois, pour faire apparaitre le menu metro, puis encore une fois pour revenir au bureau avec le menu D&eacute;marrer Classique. Et voil&agrave;!:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/6136.image_thumb7_3B903E7C.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/6136.image_5F00_thumb7_5F00_3B903E7C.png"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image_thumb[7]" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/0825.image_thumb7_thumb_6B8A6A30.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/0825.image_5F00_thumb7_5F00_thumb_5F00_6B8A6A30.png" alt="image_thumb[7]" width="310" height="405" border="0" /></a></p>]]></content:encoded>
    </item>
    <item>
      <title>How to get back the Windows 7 Start Menu in Windows 8</title>
      <link>https://docs.microsoft.com/archive/blogs/lgmorand/how-to-get-back-the-windows-7-start-menu-in-windows-8</link>
      <pubDate>Thu, 15 Sep 2011 04:40:00 GMT</pubDate>
      <dc:creator><![CDATA[Louis-Guillaume Morand]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/lgmorand/2011/09/15/how-to-get-back-the-windows-7-start-menu-in-windows-8/</guid>
      <description><![CDATA[edit : only worked on the Beta of Windows 8. Now, please install Windows 8.1 to recover the start...]]></description>
      <content:encoded><![CDATA[<p>edit : only worked on the Beta of Windows 8. Now, please install Windows 8.1 to recover the start button. <br /><br />Yesterday, Microsoft released the first preview (not a beta!) of the next version of Microsoft Windows. This version, optimized for computers/tablets, enabled to support different kinds of processors (x86, x64 or ARM) offers a new UI experience with a built-in &ldquo;Metro&rdquo; interface.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/0434.image_4B3DC5BE.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/0434.image_5F00_4B3DC5BE.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="New metro Start Menu" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/4643.image_thumb_08124791.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/4643.image_5F00_thumb_5F00_08124791.png" alt="image" width="260" height="208" border="0" /></a></p>
<p>&nbsp;</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/3630.image_135B5BCE.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/3630.image_5F00_135B5BCE.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/6232.image_thumb_0DDCC55D.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/6232.image_5F00_thumb_5F00_0DDCC55D.png" alt="image" width="655" height="330" border="0" /></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>In my case, I prefer the old menu and I&rsquo;d like to keep the new start menu screen (with the widgets) but to be allowed to use the classic menu with its lovely finder as well.</p>
<p>To do that, you just need :</p>
<ol>
<li>to open a command prompt (Win + R)</li>
<li>to type &ldquo;regedit&rdquo;</li>
<li>To go to the key <strong>HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer</strong></li>
<li>To change the value of the key <strong>RPEnabled</strong> from 1 to 0</li>
</ol>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/4667.image_703AC490.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/4667.image_5F00_703AC490.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/3568.image_thumb_3838D0AD.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/3568.image_5F00_thumb_5F00_3838D0AD.png" alt="image" width="726" height="239" border="0" /></a></p>
<p>&nbsp;</p>
<p>The change is applied without having to restart the computer. To display the old menu, you just have to click the Win key once to display the Metro menu, then to click the Win key again. And voil&agrave;!</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/7444.image_49C8BB78.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/7444.image_5F00_49C8BB78.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/6355.image_thumb_47ABBCAF.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/6355.image_5F00_thumb_5F00_47ABBCAF.png" alt="image" width="310" height="405" border="0" /></a></p>]]></content:encoded>
    </item>
    <item>
      <title>Windows 8 Dev Preview et l’erreur 0x0000225</title>
      <link>https://docs.microsoft.com/archive/blogs/lgmorand/windows-8-dev-preview-et-lerreur-0x0000225</link>
      <pubDate>Tue, 13 Sep 2011 23:40:00 GMT</pubDate>
      <dc:creator><![CDATA[Louis-Guillaume Morand]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/lgmorand/2011/09/13/windows-8-dev-preview-et-lerreur-0x0000225/</guid>
      <description><![CDATA[Alors qu’hier Microsoft faisait la keynote autour de Windows 8 la future version de son système...]]></description>
      <content:encoded><![CDATA[<p>Alors qu’hier Microsoft faisait la keynote autour de Windows 8 la future version de son système d’exploitation, est sorti ce matin la première “beta” (une preview pour être précis) de Windows 8, <strong>téléchargeable par tout le monde</strong> à l’emplacement suivant: <a title="http://msdn.microsoft.com/en-us/windows/home/" href="http://msdn.microsoft.com/en-us/windows/home/">http://msdn.microsoft.com/en-us/windows/home/</a></p>  <p>&#160;</p>  <p>Une fois téléchargé l’iso de votre choix, vous pouvez utiliser au choix <a href="http://www.microsoft.com/windows/virtual-pc/">Virtual PC</a> ou <a href="http://www.virtualbox.org/">Virtual Box</a> pour les fans du 64 bits et créer une machine virtuelle. Si le paramétrage de la machine virtuelle semble basique, vous risquez d’avoir une belle erreur au moment de l’installation notamment avec l’écran suivant : </p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/8637.image_58E81FED.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/8637.image_5F00_58E81FED.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/1374.image_thumb_50E057BE.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/1374.image_5F00_thumb_5F00_50E057BE.png" width="523" height="430" /></a></p>  <p>&#160;</p>  <p>La solution est toute simple, il faut revoir le paramétrage de la machine virtuelle et voici la liste des paramètres primordiaux:</p>  <p>Version du système:</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/7242.image_25F7CDDF.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/7242.image_5F00_25F7CDDF.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/5584.image_thumb_18EDC801.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/5584.image_5F00_thumb_5F00_18EDC801.png" width="524" height="216" /></a></p>  <p>&#160;</p>  <p>L’activation des IO-APIC</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/4118.image_36EBD5F5.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/4118.image_5F00_36EBD5F5.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/1778.image_thumb_0E00C0EC.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/1778.image_5F00_thumb_5F00_0E00C0EC.png" width="516" height="256" /></a></p>  <p>&#160;</p>  <p>et la mémoire graphique (si possible au moins 64Mo)</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/2055.image_19B6081E.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/2055.image_5F00_19B6081E.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/8713.image_thumb_29E1D017.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/8713.image_5F00_thumb_5F00_29E1D017.png" width="510" height="225" /></a></p>  <p>&#160;</p>  <p>et vous voilà avec le minimum requis pour installer et posséder une machine virtuelle sous Windows 8.</p>  <p>A noter que j’ai par ailleurs laissé les paramètres par défaut mis par Virtual Box mais qu’il peut être nécessaire d’activer l’option <strong>VT-x /AMD-v </strong>ainsi que <strong>PAE/NX</strong> pour améliorer les performances. Il en va de même pour les accélérations 2D et 3D que j’ai pour le moment laissés désactivés.</p>  <p>&#160;</p>  <p>Il est temps de voir ce que cette preview, non finie et non optimisée pour les perfs, a dans le ventre!</p>]]></content:encoded>
    </item>
    <item>
      <title>Developpement Windows Phone - partie 26</title>
      <link>https://docs.microsoft.com/archive/blogs/lgmorand/developpement-windows-phone-partie-26</link>
      <pubDate>Tue, 06 Sep 2011 13:26:00 GMT</pubDate>
      <dc:creator><![CDATA[Louis-Guillaume Morand]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/lgmorand/2011/09/06/developpement-windows-phone-partie-26/</guid>
      <description><![CDATA[D&eacute;velopper avec le GPS Windows Phone (Services de localisation)
Cet article fait partie...]]></description>
      <content:encoded><![CDATA[<h1>D&eacute;velopper avec le GPS Windows Phone (Services de localisation)</h1>
<p>Cet article fait partie d&rsquo;une s&eacute;rie d&rsquo;articles sur le d&eacute;veloppement Windows Phone. Il s&rsquo;agit d&rsquo;une traduction des articles se trouvant <a href="http://create.msdn.com/en-us/education/quickstarts" target="_blank">sur la MSDN</a>.</p>
<h2><a name="sommaire"></a>Sommaire</h2>
<p><strong>Bien d&eacute;buter et fondamentaux</strong></p>
<ul>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-1.aspx" target="_blank">Bien d&eacute;marrer (Hello World)</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-2.aspx" target="_blank">Cr&eacute;er une interface utilisateur pour Windows Phone en XAML</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-3.aspx" target="_blank">Utiliser des contr&ocirc;les</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-4.aspx" target="_blank">Types de contr&ocirc;les</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-5.aspx" target="_blank">Contr&ocirc;les Panorama et Pivot</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-6.aspx" target="_blank">Travailler avec du texte sur le Windows Phone</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-7.aspx" target="_blank">Mise en page sur l&rsquo;&eacute;cran</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-8.aspx" target="_blank">Orientations de l&rsquo;&eacute;cran</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-9.aspx" target="_blank">Saisie tactile</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-10.aspx" target="_blank">Navigation</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-11.aspx" target="_blank">Ex&eacute;cuter votre application en arri&egrave;re-plan (tombstoning)</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-12.aspx" target="_blank">Notifications Push pour le d&eacute;veloppement Windows Phone</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-13.aspx" target="_blank">Publier votre application sur le Marketplace</a></li>
</ul>
<p><strong>Visuels et m&eacute;dia</strong></p>
<ul>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-14.aspx" target="_blank">Images</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-15.aspx" target="_blank">Animations</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-16.aspx" target="_blank">Vid&eacute;o et Audio</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-17.aspx" target="_blank">Graphiques</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-18.aspx" target="_blank">Pinceaux</a></li>
</ul>
<p><strong>Travailler avec les donn&eacute;es</strong></p>
<ul>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-19.aspx" target="_blank">Obtenir des donn&eacute;es dans vos applications Windows Phone</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-20.aspx" target="_blank">Data binding</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-21.aspx" target="_blank">Isolated storage</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-22.aspx" target="_blank">Acc&eacute;der &agrave; un service Web REST</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-23.aspx" target="_blank">Consommer des donn&eacute;es Windows Azure</a></li>
</ul>
<p><strong>Sondes et autres fonctionnalit&eacute;s sp&eacute;cifiques au t&eacute;l&eacute;phone</strong></p>
<ul>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-24.aspx" target="_blank">Lanceurs et choosers</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-25.aspx" target="_blank">D&eacute;tecter des mouvements (acc&eacute;l&eacute;rom&egrave;tres)</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-26.aspx" target="_blank">D&eacute;velopper avec le GPS Windows Phone (Services de localisation)</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-27.aspx" target="_blank">D&eacute;velopper avec l&rsquo;appareil photo du Windows Phone</a></li>
</ul>
<hr />
<h1>D&eacute;velopper avec le GPS Windows Phone (Services de localisation)</h1>
<p>Silverlight pour Windows Phone inclut un espace de nom qui fournit la gestion et la surveillance en temps r&eacute;el du service de localisation du t&eacute;l&eacute;phone. Le service de localisation fournit l'information la plus pr&eacute;cise possible sur l'actuelle position du t&eacute;l&eacute;phone en utilisant une combinaison de donn&eacute;es Wi-Fi et du r&eacute;seau cellulaire, ainsi que des donn&eacute;es GPS (Global Positionning System). Le service de localisation r&eacute;cup&egrave;re la latitude, longitude, altitude, vitesse de d&eacute;placement, de direction et expose ses donn&eacute;es au travers de l'espace de nom <b>System.Devices.Location</b>.</p>
<p>Cr&eacute;er une application Windows Phone utilisant la localisation signifie que certaines fonctionnalit&eacute;s de votre application seront sujettes &agrave; la disponibilit&eacute; des donn&eacute;es de localisation. Parce que le service de localisation se base sur les signaux satellites et cellulaires, il est important d'&eacute;crire du code qui g&egrave;re les sc&eacute;narios suivants:</p>
<ul>
<li>L'utilisateur a coup&eacute; le GPS ou le r&eacute;cepteur cellulaire sur le t&eacute;l&eacute;phone.</li>
<li>La force du signal est trop faible pour recevoir les donn&eacute;es de localisation.</li>
<li>Le service de localisation est encore en cours d'initialisation ou attend que les donn&eacute;es de localisation arrivent jusqu'au t&eacute;l&eacute;phone.</li>
</ul>
<p>Nous allons coder cette application d'une fa&ccedil;on qui autorise l'utilisateur &agrave; g&eacute;rer ces sc&eacute;narios.</p>
<p>Cette QuickApp est une application qui re&ccedil;oit des donn&eacute;es du service de localisation de Windows Phone 7, et positionne les donn&eacute;es sur une carte pendant qu'il donne une information visuelle des donn&eacute;es. Cet article est divis&eacute; en chapitres:</p>
<ul>
<li><a href="#interface">Cr&eacute;er une interface utilisateur pour la lecture du service de localisation</a></li>
<li><a href="#gettinginput">Obtenir des donn&eacute;es du service de localisation en temps r&eacute;el</a></li>
<li><a href="#considerations">Consid&eacute;rations finales</a></li>
</ul>
<p><a href="http://code.msdn.microsoft.com/silverlightforphone/Release/ProjectReleases.aspx?ReleaseId=5313">T&eacute;l&eacute;chargez le code complet de cette application ici</a>.</p>
<p></p>
<h2>Proc&eacute;dure pas &agrave; pas</h2>
<p>Pour voir un exemple de ce quickstart ex&eacute;cut&eacute; sur un r&eacute;el t&eacute;l&eacute;phone, et pour construire cette application en suivant une vid&eacute;o plut&ocirc;t que de continuer &agrave; lire cet article, vous pouvez visionner la vid&eacute;o suivante. <a href="https://channel9.msdn.com/posts/Windows-Phone-7-Location-Services-GPSMaps-QuickApp-Using-Silverlight-for-Windows-Phone-7">La page pour cette vid&eacute;o</a> sur Channel 9 a plusieurs options de t&eacute;l&eacute;chargement si vous voulez une version en haute d&eacute;finition ou si vous voulez une version lisible sur des p&eacute;riph&eacute;riques mobiles.</p>
<p><object data="data:application/x-silverlight-2," type="application/x-silverlight-2" autoupdate="true" height="374" width="664"><param name="source" value="https://channel9.msdn.com/scripts/VideoPlayer.xap?v=2.1" /><param name="minRuntimeVersion" value="3.0.40624.0" /><param name="background" value="White" /><param name="autoUpgrade" value="true" /><a href="http://go.microsoft.com/fwlink/?LinkID=149156&amp;v=3.0.40624.0" style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style: none;" /> </a> </object></p>
<p></p>
<h2><a name="interface"></a>Cr&eacute;er une interface utilisateur pour la lecture du service de localisation</h2>
<p>Lancez Visual Studio et d&eacute;marrez un projet de type "Silverlight for Windows Phone". Cr&eacute;ez alors une interface utilisateur qui contient les &eacute;l&eacute;ments suivants:</p>
<ul>
<li>Six champs <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.textblock%28VS.95%29.aspx">TextBlock</a> avec des libell&eacute;s compr&eacute;hensifs pour la lecture de la longitude, de la latitude, de la vitesse et des donn&eacute;es de statut.</li>
<li>Un objet <a href="http://msdn.microsoft.com/en-us/library/ee681884.aspx">Map</a> sur lequel nous placerons un <a href="http://msdn.microsoft.com/en-us/library/microsoft.maps.mapcontrol.pushpin.aspx">Pushpin</a> affichant la position actuelle du t&eacute;l&eacute;phone.</li>
</ul>
<p>o Note: Vous aurez besoin d'une cl&eacute; Bing Maps pour pouvoir utiliser le contr&ocirc;le carte. Pour en obtenir une, suivez les instructions de l'article <a href="http://msdn.microsoft.com/en-us/library/ff428642.aspx">Obtenir une cl&eacute; Bing Maps</a>. Une fois que vous avez une cl&eacute;, qui est simplement une chaine de caract&egrave;res, entrez-la en tant que valeur pour la propri&eacute;t&eacute; <b>CredentialsProvider</b> dans le code XAML qui d&eacute;finit l'objet Map. Un exemple est fourni dans l'article <a href="http://msdn.microsoft.com/en-us/library/ee681900.aspx">Acc&eacute;dez au contr&ocirc;le gr&acirc;ce &agrave; une cl&eacute; Bing Maps</a>.</p>
<ul>
<li>Deux <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.button%28VS.95%29.aspx">Button</a>s avec un libell&eacute; explicite qui vont &ecirc;tre utilis&eacute;s pour d&eacute;marrer et arr&ecirc;ter le service de localisation ainsi que d&eacute;marrer le positionnement en temps r&eacute;el du t&eacute;l&eacute;phone sur la carte.</li>
<li>Des TextBlocks pour afficher les informations r&eacute;cup&eacute;r&eacute;es.</li>
</ul>
<p>Une proposition du positionnement de ces &eacute;l&eacute;ments est fournie ci-dessous. Ici, la valeur par d&eacute;faut des six TextBlocks est chang&eacute;e pour montrer le format et les param&egrave;tres utilis&eacute;s par le service de localisation (par exemple, "M&egrave;tres par secondes" est la valeur par d&eacute;faut pour la vitesse ainsi c'est clair).</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/7271.image_thumb1_7850DF03.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/7271.image_5F00_thumb1_5F00_7850DF03.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image_thumb1" alt="image_thumb1" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/4048.image_thumb1_thumb_7CA71430.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/4048.image_5F00_thumb1_5F00_thumb_5F00_7CA71430.png" border="0" height="596" width="325" /></a></p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:a3f92f74-82a6-4c3b-a52d-c53a75cba8a2" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">XAML</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">Grid</span><span style="color: #ff0000;"> x</span><span style="color: #0000ff;">:</span><span style="color: #ff0000;">Name</span><span style="color: #0000ff;">="ContentPanel"</span><span style="color: #ff0000;"> Grid.Row</span><span style="color: #0000ff;">="1"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="12,0,12,12"&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">TextBlock</span><span style="color: #ff0000;"> Height</span><span style="color: #0000ff;">="30"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="12,6,395,0"</span><span style="color: #ff0000;"> Name</span><span style="color: #0000ff;">="textBlock1"</span><span style="color: #ff0000;"> Text</span><span style="color: #0000ff;">="Long:"</span></li>
<li><span style="color: #ff0000;">VerticalAlignment</span><span style="color: #0000ff;">="Top" /&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">TextBlock</span><span style="color: #ff0000;"> Height</span><span style="color: #0000ff;">="30"</span><span style="color: #ff0000;"> HorizontalAlignment</span><span style="color: #0000ff;">="Left"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="12,42,0,0"</span><span style="color: #ff0000;"> Name</span><span style="color: #0000ff;">="textBlock2"</span></li>
<li><span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="Lat:"</span><span style="color: #ff0000;"> VerticalAlignment</span><span style="color: #0000ff;">="Top" /&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">TextBlock</span><span style="color: #ff0000;"> Height</span><span style="color: #0000ff;">="30"</span><span style="color: #ff0000;"> HorizontalAlignment</span><span style="color: #0000ff;">="Left"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="71,6,0,0"</span></li>
<li><span style="color: #ff0000;">Name</span><span style="color: #0000ff;">="longitudeTextBlock"</span><span style="color: #ff0000;"> Text</span><span style="color: #0000ff;">="Long"</span><span style="color: #ff0000;"> VerticalAlignment</span><span style="color: #0000ff;">="Top" /&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">TextBlock</span><span style="color: #ff0000;"> Height</span><span style="color: #0000ff;">="30"</span><span style="color: #ff0000;"> HorizontalAlignment</span><span style="color: #0000ff;">="Left"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="53,42,0,0"</span></li>
<li><span style="color: #ff0000;">Name</span><span style="color: #0000ff;">="latitudeTextBlock"</span><span style="color: #ff0000;"> Text</span><span style="color: #0000ff;">="Lat"</span><span style="color: #ff0000;"> VerticalAlignment</span><span style="color: #0000ff;">="Top" /&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #ff0000;">my</span><span style="color: #0000ff;">:</span><span style="color: #ff0000;">Map Height</span><span style="color: #0000ff;">="352"</span><span style="color: #ff0000;"> HorizontalAlignment</span><span style="color: #0000ff;">="Left"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="12,322,0,0"</span><span style="color: #ff0000;"> Name</span><span style="color: #0000ff;">="myMap"</span></li>
<li><span style="color: #ff0000;">VerticalAlignment</span><span style="color: #0000ff;">="Top"</span><span style="color: #ff0000;"> Width</span><span style="color: #0000ff;">="421"</span><span style="color: #ff0000;"> CredentialsProvider</span><span style="color: #0000ff;">="KEY"</span><span style="color: #ff0000;"> ZoomLevel</span><span style="color: #0000ff;">="1" /&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">TextBlock</span><span style="color: #ff0000;"> Height</span><span style="color: #0000ff;">="30"</span><span style="color: #ff0000;"> HorizontalAlignment</span><span style="color: #0000ff;">="Left"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="12,196,0,0"</span></li>
<li><span style="color: #ff0000;">Name</span><span style="color: #0000ff;">="textBlock3"</span><span style="color: #ff0000;"> Text</span><span style="color: #0000ff;">="Status:"</span><span style="color: #ff0000;"> VerticalAlignment</span><span style="color: #0000ff;">="Top" /&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">TextBlock</span><span style="color: #ff0000;"> Height</span><span style="color: #0000ff;">="66"</span><span style="color: #ff0000;"> HorizontalAlignment</span><span style="color: #0000ff;">="Left"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="78,196,0,0"</span></li>
<li><span style="color: #ff0000;">Name</span><span style="color: #0000ff;">="statusTextBlock"</span><span style="color: #ff0000;"> Text</span><span style="color: #0000ff;">="Status TextBlock w/TextWrapping=&amp;quot;Wrap&amp;quot;"</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">VerticalAlignment</span><span style="color: #0000ff;">="Top"</span><span style="color: #ff0000;"> Width</span><span style="color: #0000ff;">="355"</span><span style="color: #ff0000;"> TextWrapping</span><span style="color: #0000ff;">="Wrap" /&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">Button</span><span style="color: #ff0000;"> Content</span><span style="color: #0000ff;">="Track Me On Map"</span><span style="color: #ff0000;"> Height</span><span style="color: #0000ff;">="72"</span><span style="color: #ff0000;"> HorizontalAlignment</span><span style="color: #0000ff;">="Left"</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="0,256,0,0"</span><span style="color: #ff0000;"> Name</span><span style="color: #0000ff;">="trackMe"</span><span style="color: #ff0000;"> VerticalAlignment</span><span style="color: #0000ff;">="Top"</span><span style="color: #ff0000;"> Width</span><span style="color: #0000ff;">="255"</span></li>
<li><span style="color: #ff0000;">Click</span><span style="color: #0000ff;">="</span><span style="color: #ff0000;">trackMe_Click</span><span style="color: #0000ff;">" /&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">TextBlock</span><span style="color: #ff0000;"> Height</span><span style="color: #0000ff;">="30"</span><span style="color: #ff0000;"> HorizontalAlignment</span><span style="color: #0000ff;">="Left"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="12,78,0,0"</span></li>
<li><span style="color: #ff0000;">Name</span><span style="color: #0000ff;">="textBlock4"</span><span style="color: #ff0000;"> Text</span><span style="color: #0000ff;">="Speed:"</span><span style="color: #ff0000;"> VerticalAlignment</span><span style="color: #0000ff;">="Top" /&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">TextBlock</span><span style="color: #ff0000;"> Height</span><span style="color: #0000ff;">="30"</span><span style="color: #ff0000;"> HorizontalAlignment</span><span style="color: #0000ff;">="Left"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="78,78,0,0"</span></li>
<li><span style="color: #ff0000;">Name</span><span style="color: #0000ff;">="speedreadout"</span><span style="color: #ff0000;"> Text</span><span style="color: #0000ff;">="Meters Per Second"</span><span style="color: #ff0000;"> VerticalAlignment</span><span style="color: #0000ff;">="Top" /&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">TextBlock</span><span style="color: #ff0000;"> Height</span><span style="color: #0000ff;">="30"</span><span style="color: #ff0000;"> HorizontalAlignment</span><span style="color: #0000ff;">="Left"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="12,114,0,0"</span></li>
<li><span style="color: #ff0000;">Name</span><span style="color: #0000ff;">="textBlock6"</span><span style="color: #ff0000;"> Text</span><span style="color: #0000ff;">="Course:"</span><span style="color: #ff0000;"> VerticalAlignment</span><span style="color: #0000ff;">="Top" /&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">TextBlock</span><span style="color: #ff0000;"> Height</span><span style="color: #0000ff;">="30"</span><span style="color: #ff0000;"> HorizontalAlignment</span><span style="color: #0000ff;">="Left"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="84,114,0,0"</span></li>
<li><span style="color: #ff0000;">Name</span><span style="color: #0000ff;">="coursereadout"</span><span style="color: #ff0000;"> Text</span><span style="color: #0000ff;">="Heading in Degrees (0=N)"</span><span style="color: #ff0000;"> VerticalAlignment</span><span style="color: #0000ff;">="Top"</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="339" /&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">TextBlock</span><span style="color: #ff0000;"> Height</span><span style="color: #0000ff;">="30"</span><span style="color: #ff0000;"> HorizontalAlignment</span><span style="color: #0000ff;">="Left"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="12,150,0,0"</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">Name</span><span style="color: #0000ff;">="textBlock5"</span><span style="color: #ff0000;"> Text</span><span style="color: #0000ff;">="Altitude:"</span><span style="color: #ff0000;"> VerticalAlignment</span><span style="color: #0000ff;">="Top" /&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">TextBlock</span><span style="color: #ff0000;"> Height</span><span style="color: #0000ff;">="30"</span><span style="color: #ff0000;"> HorizontalAlignment</span><span style="color: #0000ff;">="Left"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="93,150,0,0"</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">Name</span><span style="color: #0000ff;">="altitudereadout"</span><span style="color: #ff0000;"> Text</span><span style="color: #0000ff;">="Altitude in Meters (0=Sea Level)"</span></li>
<li><span style="color: #ff0000;">VerticalAlignment</span><span style="color: #0000ff;">="Top" /&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">Button</span><span style="color: #ff0000;"> Content</span><span style="color: #0000ff;">="Stop LocServ"</span><span style="color: #ff0000;"> Height</span><span style="color: #0000ff;">="72"</span><span style="color: #ff0000;"> HorizontalAlignment</span><span style="color: #0000ff;">="Left"</span></li>
<li><span style="color: #ff0000;">Margin</span><span style="color: #0000ff;">="235,256,0,0"</span><span style="color: #ff0000;"> Name</span><span style="color: #0000ff;">="startStop"</span><span style="color: #ff0000;"> VerticalAlignment</span><span style="color: #0000ff;">="Top"</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="209"</span><span style="color: #ff0000;"> Click</span><span style="color: #0000ff;">="</span><span style="color: #ff0000;">startStop_Click</span><span style="color: #0000ff;">" /&gt;</span></li>
<li><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">Grid</span><span style="color: #0000ff;">&gt;</span></li>
</ol></div>
</div>
</div>
<p>Pour faire fonctionner le XAML ci-dessus, vous devez d&eacute;finir l'espace de nom "<b>my:Map</b>" qui est utilis&eacute; en ajoutant un attribut <b>xmlns</b> sur le tag <b>phone:PhoneApplicationPage</b> en haut du document XAML qui d&eacute;finit l'UI, tel que:</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:cff978e1-4afc-434d-9d45-3a23407e8a7b" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">XAML</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">phone</span><span style="color: #0000ff;">:</span><span style="color: #a31515;">PhoneApplicationPage</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">...</span></li>
<li><span style="color: #ff0000;">xmlns</span><span style="color: #0000ff;">:</span><span style="color: #ff0000;">my</span><span style="color: #0000ff;">=</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">"clr-namespace:</span><span style="color: #ff0000;">Microsoft</span><span style="color: #0000ff;">.</span><span style="color: #ff0000;">Phone</span><span style="color: #0000ff;">.</span><span style="color: #ff0000;">Controls</span><span style="color: #0000ff;">.</span><span style="color: #ff0000;">Maps</span><span style="color: #0000ff;">;assembly=Microsoft.Phone.Controls.Maps"&gt;</span></li>
</ol></div>
</div>
</div>
<p>En dernier recours, si Visual Studio ne l'a pas fait pour vous lorsque vous avez ajout&eacute; les &eacute;l&eacute;ments, ajoutez une r&eacute;f&eacute;rence vers <b>Microsoft.Phone.Controls.Maps</b>. Silverlight pour Windows Phone utilise l'assembly <b>Microsoft.Phone.Controls.Maps </b>pour fournir une fonctionnalit&eacute; de cartographie, qui doit &ecirc;tre r&eacute;f&eacute;renc&eacute;e par votre application avant que l'un de ses types, &eacute;v&egrave;nements ou m&eacute;thodes ne puisse &ecirc;tre utilis&eacute;s par votre code.</p>
<p><b>Pour ajouter Microsoft.Phone.Controls.Maps &agrave; votre application:</b></p>
<ol>
<li>Dans l'explorateur de Solution, cliquez &agrave; l'aide du bouton droit de la souris sur le n&oelig;ud <b>R&eacute;f&eacute;rences</b> de votre projet et s&eacute;lectionnez <b>Ajouter r&eacute;f&eacute;rence</b>.</li>
<li>S&eacute;lectionnez Microsoft.Phone.Controls.Maps depuis la liste et cliquez sur <b>OK</b>.</li>
</ol>
<p>Note: Visual Studio devrait automatiquement ajouter l'attribut <b>xmlns</b> et la r&eacute;f&eacute;rence vers <b>Microsoft.Phone.Controls.Maps</b> d&egrave;s que vous ajoutez le contr&ocirc;le Map sur l'interface en la glissant depuis la barre d'outils sur le designer.</p>
<p></p>
<h2><a name="gettinginput"></a>Obtenir des donn&eacute;es du service de localisation en temps r&eacute;el</h2>
<p>Dans l'explorateur de solutions, ouvrez le fichier xaml.cs file, et ajoutez les trois lignes de code suivantes en haut de la page.</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d782562b-40dc-41bf-89ec-055536e371b3" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">C#</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">using</span> Microsoft.Phone.Controls.<span style="color: #ff0000;">Maps</span>;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">using</span> System.<span style="color: #ff0000;">Device</span>.Location;</li>
<li><span style="color: #0000ff;">using</span> System.Threading;</li>
</ol></div>
</div>
</div>
<p></p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:9330ae3a-9b76-4f2d-b03b-474b75d128e0" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">Visual Basic</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">Imports</span> Microsoft.Phone.Controls.Maps</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Imports</span> System.Device.Location</li>
<li><span style="color: #0000ff;">Imports</span> System.Threading</li>
</ol></div>
</div>
</div>
<p>Cela permet &agrave; votre code C# d'acc&eacute;der au contr&ocirc;le Bing Maps, &agrave; l'API du service de localisation et au mod&egrave;le de Threading, tout ce que nous utiliserons pour cette application.</p>
<p>L'utilisation du service de localisation n&eacute;cessitera de la coordination au travers de quelques m&eacute;thodes et c'est pourquoi nous allons ajouter quelques membres &agrave; la classe principale. Le plus notable sera l'objet <b>GeoCoordinateWatcher</b>, qui re&ccedil;oit constamment les informations du service de localisation d&egrave;s qu'il est d&eacute;marr&eacute; par la m&eacute;thode <b>TryStart()</b>, que nous allons &eacute;tudier dans un moment. Nous allons appeler notre <b>watcher</b>. D&egrave;s que notre guetteur (<i>watcher</i>) a &eacute;t&eacute; d&eacute;marr&eacute;, il va essayer de r&eacute;cup&eacute;rer des informations depuis le service de localisation et exposer ces informations via ses diff&eacute;rentes propri&eacute;t&eacute;s, ainsi que d&eacute;clencher l'&eacute;v&egrave;nement <b>PositionChanged </b>lorsque l'information de position est mise &agrave; jour (c&rsquo;est-&agrave;-dire lorsque le p&eacute;riph&eacute;rique change de lieu).</p>
<p>Ce membre doit &ecirc;tre au niveau de la classe car plusieurs m&eacute;thodes vont &ecirc;tre impliqu&eacute;es dans la lecture des donn&eacute;es service de localisation pour g&eacute;rer les diff&eacute;rents &eacute;v&egrave;nements que le service va d&eacute;clencher.</p>
<p>En compl&eacute;ment, nous surveillerons si l'utilisateur a activ&eacute; le tracking sur la carte, et il s'agira encore un membre de classe. Finalement, nous utiliserons le m&ecirc;me objet <b>Pushpin </b>tout au long de l'application car nous n'en avons besoin que d'un seul, et nous mettrons &agrave; jour sa position continuellement dans diff&eacute;rentes m&eacute;thodes, et sera donc instanci&eacute; au niveau de la classe. Les trois membres ressemblent &agrave; ceci dans le code:</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:98db5f97-ba0d-4f46-8f07-a2f8c21c660c" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">C#</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">public</span> <span style="color: #ff0000;">partial</span> <span style="color: #0000ff;">class</span> <span style="color: #2b91af;">MainPage</span> : <span style="color: #2b91af;">PhoneApplicationPage</span></li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #ff0000;">GeoCoordinateWatcher</span> watcher;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">bool</span> trackingOn = <span style="color: #0000ff;">false</span>;</li>
<li><span style="color: #ff0000;">Pushpin</span> myPushpin = <span style="color: #0000ff;">new</span> <span style="color: #ff0000;">Pushpin</span>();</li>
<li style="background: #f3f3f3;">...</li>
</ol></div>
</div>
</div>
<p></p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:2d0fc698-5229-4876-b7fa-92b314dbc203" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">Visual Basic</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #ff0000;">Public</span> Partial <span style="color: #ff0000;">Class</span> MainPage</li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">Inherits</span> PhoneApplicationPage</li>
<li><span style="color: #ff0000;">Private</span> watcher <span style="color: #ff0000;">As</span> GeoCoordinateWatcher</li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">Private</span> trackingOn <span style="color: #ff0000;">As</span> Boolean = <span style="color: #ff0000;">False</span></li>
<li><span style="color: #ff0000;">Private</span> myPushpin <span style="color: #ff0000;">As</span> New <span style="color: #ff0000;">Pushpin</span>()</li>
<li style="background: #f3f3f3;">...</li>
</ol></div>
</div>
</div>
<p>Comme indiqu&eacute;, il y aura plusieurs m&eacute;thodes qui utiliseront notre <b>watcher</b>. Pour &ecirc;tre exact, il y en aura trois:</p>
<ol>
<li>Une m&eacute;thode qui g&egrave;re l'&eacute;v&egrave;nement <b>PositionChanged </b>du<b> watcher </b>et analyse les nouvelles donn&eacute;es. Nous appellerons cette m&eacute;thode <b>watcher_PositionChanged</b>.</li>
<li>Une m&eacute;thode qui g&egrave;re l'&eacute;v&egrave;nement <b>StatusChanged, </b>qui se d&eacute;clenche lorsque le service de localisation change d'&eacute;tat (inactif, initialisation, r&eacute;ception de donn&eacute;es, etc.). Nous appellerons cette m&eacute;thode <b>watcher_StatusChanged</b>.</li>
<li>Une m&eacute;thode qui g&egrave;rera le d&eacute;marrage du watcher par lui-m&ecirc;me dans son propre thread. Bien que cette m&eacute;thode ne fasse qu'une ligne de code, nous voulons compartimenter ce code pour qu'il puisse &ecirc;tre lanc&eacute; dans son propre thread et ne bloque pas l'application pendant que le service de localisation s'initialise. Nous appellerons cette m&eacute;thode <b>startLocServInBackground</b>.</li>
</ol>
<p>Nous pourrions vouloir faire cela d&egrave;s que l'application d&eacute;marre donc mettons-les dans le constructeur, la m&eacute;thode <b>MainPage()</b>.</p>
<p>Deux lignes suppl&eacute;mentaires sont n&eacute;cessaires pour instancier le watcher et mettre &agrave; jour l'interface &agrave; propos de l'initialisation du service de localisation, laissant la m&eacute;thode <b>MainPage() </b>ressembler &agrave; ceci:</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:a9b50097-65f0-4f77-9330-d580b12e85ad" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">C#</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #008000;">// Constructor</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">public</span> MainPage()</li>
<li>{</li>
<li style="background: #f3f3f3;">InitializeComponent();</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// instantiate watcher, setting its accuracy level and movement threshold.</span></li>
<li><span style="color: #ff0000;">watcher</span> = <span style="color: #0000ff;">new</span> <span style="color: #ff0000;">GeoCoordinateWatcher</span>(<span style="color: #ff0000;">GeoPositionAccuracy</span>.High); <span style="color: #008000;">// using high accuracy;</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">watcher</span>.MovementThreshold = 10.0f; <span style="color: #008000;">// meters of change before "PositionChanged"</span></li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// wire up event handlers</span></li>
<li><span style="color: #ff0000;">watcher</span>.StatusChanged += <span style="color: #0000ff;">new</span></li>
<li style="background: #f3f3f3;"><span style="color: #2b91af;">EventHandler</span>&lt;<span style="color: #ff0000;">GeoPositionStatusChangedEventArgs</span>&gt;(<span style="color: #ff0000;">watcher_StatusChanged</span>);</li>
<li><span style="color: #ff0000;">watcher</span>.PositionChanged += <span style="color: #0000ff;">new</span></li>
<li style="background: #f3f3f3;"><span style="color: #2b91af;">EventHandler</span>&lt;<span style="color: #ff0000;">GeoPositionChangedEventArgs</span>&lt;<span style="color: #ff0000;">GeoCoordinate</span>&gt;&gt;(<span style="color: #ff0000;">watcher_PositionChanged</span>);</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// start up LocServ in bg; watcher_StatusChanged will be called when complete.</span></li>
<li><span style="color: #0000ff;">new</span> <span style="color: #2b91af;">Thread</span>(<span style="color: #ff0000;">startLocServInBackground</span>).Start();</li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">statusTextBlock</span>.Text = <span style="color: #a31515;">"Starting Location Service..."</span>;</li>
<li>}</li>
</ol></div>
</div>
</div>
<p></p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:8f4c4962-0f38-407a-bfa7-1da5d803755a" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">Visual Basic</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #008000;">' Constructor</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Public</span> <span style="color: #0000ff;">Sub</span> <span style="color: #0000ff;">New</span>()</li>
<li></li>
<li style="background: #f3f3f3;">InitializeComponent()</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">' instantiate watcher, setting its accuracy level and movement threshold.</span></li>
<li>watcher = <span style="color: #0000ff;">New</span> GeoCoordinateWatcher(GeoPositionAccuracy.High)</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #008000;">' using high accuracy;</span></li>
<li style="background: #f3f3f3;">watcher.MovementThreshold = 10.0F</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">' meters of change before "PositionChanged"</span></li>
<li><span style="color: #008000;">' wire up event handlers</span></li>
<li style="background: #f3f3f3;">watcher.StatusChanged += <span style="color: #0000ff;">New</span> EventHandler(<span style="color: #0000ff;">Of</span> GeoPositionStatusChangedEventArgs)(watcher_StatusChanged)</li>
<li>watcher.PositionChanged += <span style="color: #0000ff;">New</span> EventHandler(<span style="color: #0000ff;">Of</span> GeoPositionChangedEventArgs(<span style="color: #0000ff;">Of</span> GeoCoordinate))(watcher_PositionChanged)</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #008000;">' start up LocServ in bg; watcher_StatusChanged will be called when complete.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">New</span> Thread(startLocServInBackground).Start()</li>
<li>statusTextBlock.Text = <span style="color: #a31515;">"Starting Location Service..."</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Sub</span></li>
</ol></div>
</div>
</div>
<p>Il est maintenant temps d'impl&eacute;menter les gestionnaires d'&eacute;v&egrave;nements. Commen&ccedil;ons avec <b>watcher_StatusChanged</b>. <b>watcher</b> donnera son statut &agrave; la m&eacute;thode <b>watcher_StatusChanged</b> en utilisant un objet <b>GeoPositionStatusChangedEventArgs</b> pass&eacute; en argument. Cet objet a une propri&eacute;t&eacute; <i>enum</i> appel&eacute;e <b>GeoPositionStatus</b> qui fournit des noms compr&eacute;hensibles pour les diff&eacute;rents &eacute;tats du service de localisation. Tout ce que nous voulons faire dans notre application est de notifier l'utilisateur lorsque le statut a chang&eacute; et nous pouvons accomplir cela avec un seul <b>switch</b> qui g&egrave;re les quatre valeurs possibles <b>GeoPositionStatus</b>:</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:f30752cb-4887-4462-8a98-5d07e13e348b" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">C#</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">void</span> watcher_StatusChanged(<span style="color: #0000ff;">object</span> sender, <span style="color: #ff0000;">GeoPositionStatusChangedEventArgs</span> e)</li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #0000ff;">switch</span> (<span style="color: #ff0000;">e</span>.Status)</li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #0000ff;">case</span> <span style="color: #ff0000;">GeoPositionStatus</span>.Disabled:</li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// The Location Service is disabled or unsupported.</span></li>
<li><span style="color: #008000;">// Check to see if the user has disabled the Location Service.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">if</span> (<span style="color: #ff0000;">watcher</span>.Permission == <span style="color: #ff0000;">GeoPositionPermission</span>.Denied)</li>
<li>{</li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// The user has disabled the Location Service on their device.</span></li>
<li><span style="color: #ff0000;">statusTextBlock</span>.Text = <span style="color: #a31515;">"You have disabled Location Service."</span>;</li>
<li style="background: #f3f3f3;">}</li>
<li><span style="color: #0000ff;">else</span></li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #ff0000;">statusTextBlock</span>.Text = <span style="color: #a31515;">"Location Service is not functioning on this device."</span>;</li>
<li style="background: #f3f3f3;">}</li>
<li><span style="color: #0000ff;">break</span>;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">case</span> <span style="color: #ff0000;">GeoPositionStatus</span>.Initializing:</li>
<li><span style="color: #ff0000;">statusTextBlock</span>.Text = <span style="color: #a31515;">"Location Service is retrieving data..."</span>;</li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// The Location Service is initializing.</span></li>
<li><span style="color: #0000ff;">break</span>;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">case</span> <span style="color: #ff0000;">GeoPositionStatus</span>.NoData:</li>
<li><span style="color: #008000;">// The Location Service is working, but it cannot get location data.</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">statusTextBlock</span>.Text = <span style="color: #a31515;">"Location data is not available."</span>;</li>
<li><span style="color: #0000ff;">break</span>;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">case</span> <span style="color: #ff0000;">GeoPositionStatus</span>.Ready:</li>
<li><span style="color: #008000;">// The Location Service is working and is receiving location data.</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">statusTextBlock</span>.Text = <span style="color: #a31515;">"Location data is available."</span>;</li>
<li><span style="color: #0000ff;">break</span>;</li>
<li style="background: #f3f3f3;">}</li>
<li>}</li>
</ol></div>
</div>
</div>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:3efbe7b5-3c9b-44ae-8494-5164239d8920" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">Visual Basic</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">Private</span> <span style="color: #0000ff;">Sub</span> watcher_StatusChanged(sender <span style="color: #0000ff;">As</span> <span style="color: #0000ff;">Object</span>, e <span style="color: #0000ff;">As</span> GeoPositionStatusChangedEventArgs)</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Select</span> <span style="color: #0000ff;">Case</span> e.Status</li>
<li><span style="color: #0000ff;">Case</span> GeoPositionStatus.Disabled</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #008000;">' The Location Service is disabled or unsupported.</span></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">' Check to see if the user has disabled the Location Service.</span></li>
<li><span style="color: #0000ff;">If</span> watcher.Permission = GeoPositionPermission.Denied <span style="color: #0000ff;">Then</span></li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #008000;">' The user has disabled the Location Service on their device.</span></li>
<li style="background: #f3f3f3;">statusTextBlock.Text = <span style="color: #a31515;">"You have disabled Location Service."</span></li>
<li><span style="color: #0000ff;">Else</span></li>
<li style="background: #f3f3f3;">statusTextBlock.Text = <span style="color: #a31515;">"Location Service is not functioning on this device."</span></li>
<li><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">If</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Exit Select</span></li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Case</span> GeoPositionStatus.Initializing</li>
<li>statusTextBlock.Text = <span style="color: #a31515;">"Location Service is retrieving data..."</span></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">' The Location Service is initializing.</span></li>
<li><span style="color: #0000ff;">Exit Select</span></li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #0000ff;">Case</span> GeoPositionStatus.NoData</li>
<li style="background: #f3f3f3;"><span style="color: #008000;">' The Location Service is working, but it cannot get location data.</span></li>
<li>statusTextBlock.Text = <span style="color: #a31515;">"Location data is not available."</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Exit Select</span></li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Case</span> GeoPositionStatus.Ready</li>
<li><span style="color: #008000;">' The Location Service is working and is receiving location data.</span></li>
<li style="background: #f3f3f3;">statusTextBlock.Text = <span style="color: #a31515;">"Location data is available."</span></li>
<li><span style="color: #0000ff;">Exit Select</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Select</span></li>
<li><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Sub</span></li>
</ol></div>
</div>
</div>
<p>Maintenant que nous pouvons voir ce qui va se passer lorsque le service de localisation sera activ&eacute; et que l'&eacute;v&egrave;nement <b>StatusChanged</b> est d&eacute;clench&eacute;, impl&eacute;mentons la m&eacute;thode qui s'occupe de l'initialisation et que l'on appellera <b>startLocServInBackground</b>. Cette m&eacute;thode consistera en une seule ligne qui appelle la m&eacute;thode <b>TryStart</b> de notre watcher, en sp&eacute;cifiant un timeout de 60 secondes pour l'initialisation. Parce que la m&eacute;thode T<b>ryStart</b> est synchrone, cela pourrait bloquer l'application sur une longue p&eacute;riode si nous ne l'avions pas la lancer en arri&egrave;re-plan, d'o&ugrave; l'utilisation d'un nouveau thread dans l'appel de <b>startLocServInBackground</b> dans la m&eacute;thode <b>MainPage</b>. Le thread que nous avons d&eacute;marr&eacute; dans <b>MainPage</b> sera automatiquement ar&ecirc;te avec la p&eacute;riode de timeout de la method <b>TryStart</b> ou lorsque le <b>watcher</b> est initialis&eacute; avec succ&egrave;s et l&rsquo;&eacute;v&egrave;nement <b>watcher_StatusChanged</b> est d&eacute;j&agrave; impl&eacute;ment&eacute; pour g&eacute;rer tout ce qui passe apr&egrave;s l&rsquo;initialisation :</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:66604555-47f4-4558-be8b-3ccf1447ef2c" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">C#</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">void</span> startLocServInBackground()</li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #ff0000;">watcher</span>.TryStart(<span style="color: #0000ff;">true</span>, <span style="color: #2b91af;">TimeSpan</span>.FromMilliseconds(60000));</li>
<li style="background: #f3f3f3;">}</li>
</ol></div>
</div>
</div>
<p></p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:ccdf72b4-df46-450e-8f3e-d51aeb815f3c" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">Visual Basic</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">Private</span> <span style="color: #0000ff;">Sub</span> startLocServInBackground()</li>
<li style="background: #f3f3f3;">watcher.TryStart(<span style="color: #0000ff;">True</span>, <span style="color: #2b91af;">TimeSpan</span>.FromMilliseconds(60000))</li>
<li><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Sub</span></li>
</ol></div>
</div>
</div>
<p>Avant que nous n'impl&eacute;mentions <b>watcher_PositionChanged</b>, c&acirc;blons deux boutons qui vont affecter le comportement de l'application lorsque le t&eacute;l&eacute;phone change de position. Nous appellerons ces deux boutons "Track Me On Map" et "Stop LocServ," et dans le XAML, vous verrez que nous avons sp&eacute;cifi&eacute; des gestionnaires pour l'&eacute;v&egrave;nement <b>Click </b>pour chacun de ces boutons, nomm&eacute;s respectivement <b>trackMe_Click</b> et <b>startStop_Click</b>.</p>
<p>Ces deux m&eacute;thodes sont li&eacute;es &agrave; l'activation et la d&eacute;sactivation du service de localisation, la valeur bool&eacute;enne <b>trackingOn</b> ainsi que <b>watcher_PositionChanged</b> met &agrave; jour ou non l'objet carte pour afficher la position actuelle du t&eacute;l&eacute;phone. De plus, un petit travail d'interface est fait pour modifier l'affichage du bouton et fournir un message de statut.</p>
<p>Un appel int&eacute;ressant &agrave; l'objet <b>Map</b> est fait dans la m&eacute;thode <b>trackMe_Click</b>. Si l'utilisateur sp&eacute;cifie qu'il veut voir sa position actuelle sur la carte, le niveau de zoom sur la carte passe de 1.0 (zoom arri&egrave;re pour montrer la plan&egrave;te enti&egrave;re) &agrave; 16.0 (zoom au niveau des rues).</p>
<p>L'activation du service de localisation se fait encore en arri&egrave;re-plan en utilisant <b>startLocServInBackground</b>. Les deux m&eacute;thodes ressemblent &agrave; ceci:</p>
<p></p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:0e5f5183-a754-48ca-9acb-c9332a5fc871" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">C#</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> trackMe_Click(<span style="color: #0000ff;">object</span> sender, <span style="color: #ff0000;">RoutedEventArgs</span> e)</li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #0000ff;">if</span> (<span style="color: #ff0000;">trackingOn</span>)</li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #ff0000;">trackMe</span>.Content = <span style="color: #a31515;">"Track Me On Map"</span>;</li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">trackingOn</span> = <span style="color: #0000ff;">false</span>;</li>
<li><span style="color: #ff0000;">myMap</span>.ZoomLevel = 1.0f;</li>
<li style="background: #f3f3f3;">}</li>
<li><span style="color: #0000ff;">else</span></li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #ff0000;">trackMe</span>.Content = <span style="color: #a31515;">"Stop Tracking"</span>;</li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">trackingOn</span> = <span style="color: #0000ff;">true</span>;</li>
<li><span style="color: #ff0000;">myMap</span>.ZoomLevel = 16.0f;</li>
<li style="background: #f3f3f3;">}</li>
<li>}</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> startStop_Click(<span style="color: #0000ff;">object</span> sender, <span style="color: #ff0000;">RoutedEventArgs</span> e)</li>
<li style="background: #f3f3f3;">{</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">if</span> (<span style="color: #ff0000;">startStop</span>.Content.ToString() == <span style="color: #a31515;">"Stop LocServ"</span>)</li>
<li>{</li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">startStop</span>.Content = <span style="color: #a31515;">"Start LocServ"</span>;</li>
<li><span style="color: #ff0000;">statusTextBlock</span>.Text = <span style="color: #a31515;">"Location Services stopped..."</span>;</li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">watcher</span>.Stop();</li>
<li>}</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span> (<span style="color: #ff0000;">startStop</span>.Content.ToString() == <span style="color: #a31515;">"Start LocServ"</span>)</li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #ff0000;">startStop</span>.Content = <span style="color: #a31515;">"Stop LocServ"</span>;</li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">statusTextBlock</span>.Text = <span style="color: #a31515;">"Starting Location Services..."</span>;</li>
<li><span style="color: #0000ff;">new</span> <span style="color: #2b91af;">Thread</span>(<span style="color: #ff0000;">startLocServInBackground</span>).Start();</li>
<li style="background: #f3f3f3;">}</li>
<li>}</li>
</ol></div>
</div>
</div>
<p></p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1b7e7b95-8792-442c-8ebb-71f024f6d570" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">Visual Basic</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">Private</span> <span style="color: #0000ff;">Sub</span> trackMe_Click(sender <span style="color: #0000ff;">As</span> <span style="color: #0000ff;">Object</span>, e <span style="color: #0000ff;">As</span> RoutedEventArgs)</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #0000ff;">If</span> trackingOn <span style="color: #0000ff;">Then</span></li>
<li style="background: #f3f3f3;">trackMe.Content = <span style="color: #a31515;">"Track Me On Map"</span></li>
<li>trackingOn = <span style="color: #0000ff;">False</span></li>
<li style="background: #f3f3f3;">myMap.ZoomLevel = 1.0F</li>
<li><span style="color: #0000ff;">Else</span></li>
<li style="background: #f3f3f3;">trackMe.Content = <span style="color: #a31515;">"Stop Tracking"</span></li>
<li>trackingOn = <span style="color: #0000ff;">True</span></li>
<li style="background: #f3f3f3;">myMap.ZoomLevel = 16.0F</li>
<li><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">If</span></li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Sub</span></li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #0000ff;">Private</span> <span style="color: #0000ff;">Sub</span> startStop_Click(sender <span style="color: #0000ff;">As</span> <span style="color: #0000ff;">Object</span>, e <span style="color: #0000ff;">As</span> RoutedEventArgs)</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #0000ff;">If</span> startStop.Content.ToString() = <span style="color: #a31515;">"Stop LocServ"</span> <span style="color: #0000ff;">Then</span></li>
<li style="background: #f3f3f3;">startStop.Content = <span style="color: #a31515;">"Start LocServ"</span></li>
<li>statusTextBlock.Text = <span style="color: #a31515;">"Location Services stopped..."</span></li>
<li style="background: #f3f3f3;">watcher.[Stop]()</li>
<li><span style="color: #0000ff;">ElseIf</span> startStop.Content.ToString() = <span style="color: #a31515;">"Start LocServ"</span> <span style="color: #0000ff;">Then</span></li>
<li style="background: #f3f3f3;">startStop.Content = <span style="color: #a31515;">"Stop LocServ"</span></li>
<li>statusTextBlock.Text = <span style="color: #a31515;">"Starting Location Services..."</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">New</span> Thread(startLocServInBackground).Start()</li>
<li><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">If</span></li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Sub</span></li>
</ol></div>
</div>
</div>
<p>Enfin, il y a la m&eacute;thode <b>watcher_PositionChanged</b> qui g&egrave;re l'&eacute;v&egrave;nement <b>PositionChanged</b>,. Cette m&eacute;thode re&ccedil;oit des informations &agrave; propos de la position actuellement dans l'objet <b>GeoPositionChangedEventArgs</b>, qui est pass&eacute; en argument. Cet objet contient les informations &agrave; propos du p&eacute;riph&eacute;rique, sa longitude, sa latitude, sa vitesse (en m&egrave;tres par seconde), sa direction (une valeur flottante entre 0 et 360) et m&ecirc;me l'altitude (en m&egrave;tres au dessus du niveau de la mer). Nous allons afficher toutes ces donn&eacute;es dans l'&eacute;cran que nous avons cr&eacute;&eacute; plus t&ocirc;t.</p>
<p>De plus, si l'utilisateur a cliqu&eacute; le bouton "Track Me On Map", alors la variable <b>trackingOn</b> est d&eacute;finie &agrave; "true," et que la carte est zoom&eacute;e au niveau de la rue, ainsi, dans la m&eacute;thode <b>watcher_PositionChanged</b> nous v&eacute;rifions la valeur <b>trackingOn</b>' et centrons la carte sur notre position actuelle si sa valeur est <i>true.</i> La m&eacute;thode finale ressemble &agrave; ceci:</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:a3b70523-a753-43d7-8334-c4bc6906b137" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">C#</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">void</span> watcher_PositionChanged(<span style="color: #0000ff;">object</span> sender, <span style="color: #ff0000;">GeoPositionChangedEventArgs</span>&lt;<span style="color: #ff0000;">GeoCoordinate</span>&gt; e)</li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #008000;">//update the TextBlock readouts</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">latitudeTextBlock</span>.Text = <span style="color: #ff0000;">e</span>.Position.Location.Latitude.ToString(<span style="color: #a31515;">"0.0000000000000"</span>);</li>
<li><span style="color: #ff0000;">longitudeTextBlock</span>.Text = <span style="color: #ff0000;">e</span>.Position.Location.Longitude.ToString(<span style="color: #a31515;">"0.0000000000000"</span>);</li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">speedreadout</span>.Text = <span style="color: #ff0000;">e</span>.Position.Location.Speed.ToString(<span style="color: #a31515;">"0.0"</span>) + <span style="color: #a31515;">" meters per second"</span>;</li>
<li><span style="color: #ff0000;">coursereadout</span>.Text = <span style="color: #ff0000;">e</span>.Position.Location.Course.ToString(<span style="color: #a31515;">"0.0"</span>);</li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">altitudereadout</span>.Text = <span style="color: #ff0000;">e</span>.Position.Location.Altitude.ToString(<span style="color: #a31515;">"0.0"</span>);</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// update the Map if the user has asked to be tracked.</span></li>
<li><span style="color: #0000ff;">if</span> (<span style="color: #ff0000;">trackingOn</span>)</li>
<li style="background: #f3f3f3;">{</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// center the pushpin and map on the current position</span></li>
<li><span style="color: #ff0000;">myPushpin</span>.Location = <span style="color: #ff0000;">e</span>.Position.Location;</li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">myMap</span>.Center = <span style="color: #ff0000;">e</span>.Position.Location;</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// if this is the first time that myPushpin is being plotted, plot it!</span></li>
<li><span style="color: #0000ff;">if</span> (<span style="color: #ff0000;">myMap</span>.Children.Contains(<span style="color: #ff0000;">myPushpin</span>) == <span style="color: #0000ff;">false</span>) {<span style="color: #ff0000;">myMap</span>.Children.Add(<span style="color: #ff0000;">myPushpin</span>);};</li>
<li style="background: #f3f3f3;">}</li>
<li>}</li>
</ol></div>
</div>
</div>
<p></p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:2b928cb6-0048-488f-851f-a16ac5c0e2d0" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">Visual Basic</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">Private</span> <span style="color: #0000ff;">Sub</span> watcher_PositionChanged(sender <span style="color: #0000ff;">As</span> <span style="color: #0000ff;">Object</span>, e <span style="color: #0000ff;">As</span> GeoPositionChangedEventArgs(<span style="color: #0000ff;">Of</span> GeoCoordinate))</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #008000;">' met jour les liblls</span></li>
<li style="background: #f3f3f3;">latitudeTextBlock.Text = e.Position.Location.Latitude.ToString(<span style="color: #a31515;">"0.0000000000000"</span>)</li>
<li>longitudeTextBlock.Text = e.Position.Location.Longitude.ToString(<span style="color: #a31515;">"0.0000000000000"</span>)</li>
<li style="background: #f3f3f3;">speedreadout.Text = e.Position.Location.Speed.ToString(<span style="color: #a31515;">"0.0"</span>) &amp; <span style="color: #a31515;">" meters per second"</span></li>
<li>coursereadout.Text = e.Position.Location.Course.ToString(<span style="color: #a31515;">"0.0"</span>)</li>
<li style="background: #f3f3f3;">altitudereadout.Text = e.Position.Location.Altitude.ToString(<span style="color: #a31515;">"0.0"</span>)</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">' met jour la carte si l'utilisateur a demand connaitre sa position.</span></li>
<li><span style="color: #0000ff;">If</span> trackingOn <span style="color: #0000ff;">Then</span></li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #008000;">' centre la punaise et la carte sur la position actuelle</span></li>
<li style="background: #f3f3f3;">myPushpin.Location = e.Position.Location</li>
<li>myMap.Center = e.Position.Location</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #008000;">' si c'est le premire fois que la punaise est plante, on la plante!</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">If</span> myMap.Children.Contains(myPushpin) = <span style="color: #0000ff;">False</span> <span style="color: #0000ff;">Then</span></li>
<li>myMap.Children.Add(myPushpin)</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">If</span></li>
<li><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">If</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Sub</span></li>
</ol></div>
</div>
</div>
<p>Cette application est maintenant compl&egrave;te et vous avez un exemple de programme qui est structur&eacute; pour r&eacute;pondre &agrave; l'initialisation synchrone du service de localisation, pour garder trace du statut courant du service (qui est sujet &agrave; la qualit&eacute; des signaux GPS et cellulaire) et aussi pour positionner une punaise sur une carte Bing qui affiche &agrave; la demande les rues ou la vue satellite.</p>
<p></p>
<h2></h2>
<h2><a name="considerations"></a>Consid&eacute;rations finales</h2>
<ul>
<li>Nous utilisons le param&eacute;trage high-accuracy dans cette application ce qui consomm&eacute; rapidement la batterie du telephone. Essayez d&rsquo;utiliser <b>GeoPositionAccuracy.Default</b> autant que possible, comme par exemple lorsque votre application recherche dans les environs.</li>
<li>Le param&eacute;trage <b>MovementThreshold</b> est un &eacute;l&eacute;ment cl&eacute; de la consommation de la batterie, parce qu'en g&eacute;n&eacute;ral, les donn&eacute;es de position sont cons&eacute;quentes et l&rsquo;application ne devrait pas r&eacute;pondre &agrave; chaque fluctuation des donn&eacute;es. Si l&rsquo;&eacute;v&egrave;nement <b>PositionChanged</b> est d&eacute;clench&eacute; trop fr&eacute;quemment, la batterie et le temps de processeur seront consomm&eacute;s avec g&acirc;chis.</li>
<li>Parce que le service de localisation utilise une combinaison de donn&eacute;es Wi-Fi, cellulaires et GPS, la position devient de plus en plus pr&eacute;cise apr&egrave;s que le service ait &eacute;t&eacute; d&eacute;marr&eacute; et au fur et &agrave; mesure qu'il re&ccedil;oit des donn&eacute;es. Les informations de r&eacute;seau Wi-Fi et cellulaire sont g&eacute;n&eacute;ralement re&ccedil;ues en quelques secondes pendant que les donn&eacute;es GPS peuvent prendre plusieurs minutes.</li>
<li>L'objet <b>GeoCoordinateWatcher</b> d&eacute;clenche des &eacute;v&egrave;nements dans le thread UI. Cela signifie que vous voudrez r&eacute;aliser le moins de travail possible dans les fonctions de gestionnaires des &eacute;v&egrave;nements <b>PositionChanged </b>et <b>StatusChanged</b>, ou n'importe quel autre &eacute;v&egrave;nement <b>GeoCoordinateWatcher</b>. Si un traitement important a besoin d'&ecirc;tre fait lorsque ces &eacute;v&egrave;nements sont d&eacute;clench&eacute;s, ayez des fonctions de traitement agissant dans des threads d'arri&egrave;re-plan pour &eacute;viter que l'interface ne se fige.</li>
</ul>
<p></p>
<h2>Voir aussi</h2>
<ul>
<li><a href="http://code.msdn.microsoft.com/silverlightforphone/Release/ProjectReleases.aspx?ReleaseId=5313">Source Code For This QuickApp</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.device.location%28v=VS.92%29.aspx">System.Device.Location Namespace</a> (Reference Docs)</li>
<li><a href="http://msdn.microsoft.com/en-us/library/ee681884.aspx">Bing Maps Silverlight Control </a>(Reference Docs)</li>
<li><a href="http://msdn.microsoft.com/en-us/library/ff431803%28v=VS.92%29.aspx">Location for Windows Phone</a> (How To Docs)</li>
</ul>
<hr />
<p><a href="#sommaire">Cliquez ici pour revenir au sommaire de la liste d&rsquo;articles</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Developpement Windows Phone - partie 23</title>
      <link>https://docs.microsoft.com/archive/blogs/lgmorand/developpement-windows-phone-partie-23</link>
      <pubDate>Tue, 06 Sep 2011 13:23:00 GMT</pubDate>
      <dc:creator><![CDATA[Louis-Guillaume Morand]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/lgmorand/2011/09/06/developpement-windows-phone-partie-23/</guid>
      <description><![CDATA[Consommer un service Windows Azure Data avec OData
Cet article fait partie d&rsquo;une s&eacute;rie...]]></description>
      <content:encoded><![CDATA[<h1>Consommer un service Windows Azure Data avec OData</h1>
<p>Cet article fait partie d&rsquo;une s&eacute;rie d&rsquo;articles sur le d&eacute;veloppement Windows Phone. Il s&rsquo;agit d&rsquo;une traduction des articles se trouvant <a href="http://create.msdn.com/en-us/education/quickstarts" target="_blank">sur la MSDN</a>.</p>
<h2><a name="sommaire"></a>Sommaire</h2>
<p><strong>Bien d&eacute;buter et fondamentaux</strong></p>
<ul>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-1.aspx" target="_blank">Bien d&eacute;marrer (Hello World)</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-2.aspx" target="_blank">Cr&eacute;er une interface utilisateur pour Windows Phone en XAML</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-3.aspx" target="_blank">Utiliser des contr&ocirc;les</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-4.aspx" target="_blank">Types de contr&ocirc;les</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-5.aspx" target="_blank">Contr&ocirc;les Panorama et Pivot</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-6.aspx" target="_blank">Travailler avec du texte sur le Windows Phone</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-7.aspx" target="_blank">Mise en page sur l&rsquo;&eacute;cran</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-8.aspx" target="_blank">Orientations de l&rsquo;&eacute;cran</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-9.aspx" target="_blank">Saisie tactile</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-10.aspx" target="_blank">Navigation</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-11.aspx" target="_blank">Ex&eacute;cuter votre application en arri&egrave;re-plan (tombstoning)</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-12.aspx" target="_blank">Notifications Push pour le d&eacute;veloppement Windows Phone</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-13.aspx" target="_blank">Publier votre application sur le Marketplace</a></li>
</ul>
<p><strong>Visuels et m&eacute;dia</strong></p>
<ul>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-14.aspx" target="_blank">Images</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-15.aspx" target="_blank">Animations</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-16.aspx" target="_blank">Vid&eacute;o et Audio</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-17.aspx" target="_blank">Graphiques</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-18.aspx" target="_blank">Pinceaux</a></li>
</ul>
<p><strong>Travailler avec les donn&eacute;es</strong></p>
<ul>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-19.aspx" target="_blank">Obtenir des donn&eacute;es dans vos applications Windows Phone</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-20.aspx" target="_blank">Data binding</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-21.aspx" target="_blank">Isolated storage</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-22.aspx" target="_blank">Acc&eacute;der &agrave; un service Web REST</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-23.aspx" target="_blank">Consommer des donn&eacute;es Windows Azure</a></li>
</ul>
<p><strong>Sondes et autres fonctionnalit&eacute;s sp&eacute;cifiques au t&eacute;l&eacute;phone</strong></p>
<ul>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-24.aspx" target="_blank">Lanceurs et choosers</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-25.aspx" target="_blank">D&eacute;tecter des mouvements (acc&eacute;l&eacute;rom&egrave;tres)</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-26.aspx" target="_blank">D&eacute;velopper avec le GPS Windows Phone (Services de localisation)</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-27.aspx" target="_blank">D&eacute;velopper avec l&rsquo;appareil photo du Windows Phone</a></li>
</ul>
<hr />
<h1>Consommer un service Windows Azure Data avec OData</h1>
<p>Le protocole Open Data (OData) est bas&eacute; sur une entit&eacute; et un mod&egrave;le de relation qui vous permet d'acc&eacute;der &agrave; des donn&eacute;es REST. OData autorise l'utilisation protocole standard HTTP pour ex&eacute;cuter des requ&ecirc;tes, et m&ecirc;me cr&eacute;er, mettre &agrave; jour et supprimer des donn&eacute;es depuis un service de donn&eacute;es. En utilisant la biblioth&egrave;que de client OData pour Windows Phone, votre application peut consommer des donn&eacute;es d'un service Windows Azure ou n'importe quel autre service qui supporte le protocole OData. La biblioth&egrave;que cliente g&eacute;n&egrave;re des requ&ecirc;tes HTTP vers un service OData et transforme les donn&eacute;es dans le flux de r&eacute;ponse en objets sur le client.</p>
<p>Remarque</p>
<p>Le client OData pour Windows Phone 7 est disponible en tant que biblioth&egrave;que s&eacute;par&eacute;e, que vous pouvez t&eacute;l&eacute;charger et installer depuis la page <a href="http://go.microsoft.com/fwlink/?LinkId=207900">Open Data Protocol&mdash;client libraries</a>.</p>
<p>Ce tutoriel contient les sections suivantes:</p>
<ul>
<li><a href="#ODataServicesOverview">Survol des services OData pour Windows Phone</a></li>
<li><a href="#BindingData">Lier des donn&eacute;es aux contr&ocirc;les</a></li>
<li><a href="#PagingNavigation">Pagination et Navigation</a></li>
<li><a href="#MaintainingState">Maintenir l'&eacute;tat d'application</a></li>
<li><a href="#AddServiceReference">G&eacute;n&eacute;rer les classes de donn&eacute;es du client</a></li>
</ul>
<p>Les exemples de ce tutoriel utilisent Silverlight dans un navigateur pour simuler le comportement sur Windows Phone. Le r&eacute;sultat peut &ecirc;tre sensiblement diff&eacute;rent sur un p&eacute;riph&eacute;rique Windows Phone.</p>
<p></p>
<h2></h2>
<h2><a name="ODataServicesOverview"></a>Survol des services OData pour Windows Phone</h2>
<p>Les applications pour p&eacute;riph&eacute;riques mobiles se basent &eacute;norm&eacute;ment sur des sources de donn&eacute;es distantes, et la plateforme Windows Azure fournit une excellente source de donn&eacute;es pour vos applications Windows Phone. OData est l'un des principaux m&eacute;canismes d'acc&egrave;s aux donn&eacute;es de la plateforme Windows Azure. Plusieurs composants de la plateforme Windows Azure fournissent des flux OData, incluant Windows Azure Table Storage, Microsoft SQL Azure, et Windows Azure Marketplace DataMarket. Une liste des flux OData est disponible sur <a href="http://go.microsoft.com/fwlink/?LinkId=212400">site Web du protocole Open Data</a>.</p>
<p>Vous pouvez aussi utiliser des services de donn&eacute;es WCF pour exposer vos propres donn&eacute;es en tant que flux OData qui peuvent &ecirc;tre consomm&eacute;es par des applications qui s'ex&eacute;cutent sur une vari&eacute;t&eacute; de plateformes, incluant Windows Phone. Pour plus d'informations, lisez <a href="http://go.microsoft.com/fwlink/?LinkID=155035">WCF Data Services</a>.</p>
<p>Comme exemple, Netflix expose leur catalogue de films en tant que flux OData h&eacute;berg&eacute; dans le Cloud. Nous consommons ce flux OData public dans l'exemple suivant:</p>
<p>Cliquez la tuile OData sur le t&eacute;l&eacute;phone pour d&eacute;marrer l'exemple OData. Sur le t&eacute;l&eacute;phone, lorsque vous tapez le bouton Next Page, la page suivante est charg&eacute;e depuis le service de donn&eacute;es. Lorsque vous cliquez sur un &eacute;l&eacute;ment de la liste, les informations d&eacute;taill&eacute;es de l'&eacute;l&eacute;ment s&eacute;lectionn&eacute; sont affich&eacute;es. Dans cet exemple, le bouton Back du t&eacute;l&eacute;phone, agit comme il le fait sur le t&eacute;l&eacute;phone en vous faisant revenir &agrave; la page pr&eacute;c&eacute;dente. Vous pouvez t&eacute;l&eacute;charger le projet complet dans la galerie de code <a href="http://go.microsoft.com/fwlink/?LinkId=212640">Silverlight for Windows Phone</a>.</p>
<p></p>
<h2></h2>
<h2><a name="BindingData"></a>Lier des donn&eacute;es aux contr&ocirc;les</h2>
<p>Dans la biblioth&egrave;que cliente Odata pour Windows Phone 7, la classe DataServiceCollection repr&eacute;sente une collection dynamique de donn&eacute;es li&eacute;es, qui fournit des notifications lorsque des &eacute;l&eacute;ments sont ajout&eacute;s ou supprim&eacute;s de la collection. Une requ&ecirc;te bas&eacute;e sur une URI d&eacute;termine quelles donn&eacute;es la collection va contenir. Cette URI est sp&eacute;cifi&eacute;e en tant que param&egrave;tre dans la m&eacute;thode LoadAsync de la classe DataServiceCollection. Lorsqu'elle est ex&eacute;cut&eacute;e, cette m&eacute;thode retourne un flux OData qui est mat&eacute;rialis&eacute; par des objets de donn&eacute;es dans la collection li&eacute;e. Les objets mat&eacute;rialis&eacute;s sont g&eacute;r&eacute;s par la classe DataServiceCollection qui s'assure que les r&eacute;sultats sont envoy&eacute;s sur le bon thread et ainsi vous n'avez pas besoin d'un objet Dispatcher. Pour plus d'informations sur l'utilisation de biblioth&egrave;que OData, lisez l'article <a href="http://go.microsoft.com/fwlink/?LinkId=212411">Open Data Protocol (OData) Overview for Windows Phone</a>.</p>
<p>Parce que les applications Windows Phone requi&egrave;rent une navigation entre diff&eacute;rentes pages, vous devriez utiliser un design pattern Model-View-ViewModel (MVVM) pour vos applications de donn&eacute;es. Dans ce pattern, le mod&egrave;le est g&eacute;n&eacute;r&eacute; par des outils bas&eacute;s sur les metadata retourn&eacute;es par le service de donn&eacute;es, la vue est form&eacute;e par tous les contr&ocirc;l&eacute;s li&eacute;s de la page, et le ViewModel est un composant partag&eacute; qui s'occupe d'acc&eacute;der au service de donn&eacute;es et expose les donn&eacute;es qui sont li&eacute;es &agrave; la vue. En utilisant cette approche, vous pouvez exposer le DataServiceContext en tant que propri&eacute;t&eacute; de la classe ViewModel, &agrave; c&ocirc;t&eacute; des propri&eacute;t&eacute;s qui retournent des instances de DataServiceCollection ou n'importe quelles autres valeurs dynamiques qui sont li&eacute;es aux contr&ocirc;les dans la vue. Le viewModel doit aussi exposer toutes les propri&eacute;t&eacute;s qui doivent &ecirc;tre enregistr&eacute;es lorsque l'application est d&eacute;sactiv&eacute;e, ce que nous discuterons dans une section plus loin. Le diagramme objet suivant repr&eacute;sente la classe MainViewModel de notre exemple:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/3343.image_thumb2_7A2A1E6F.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/3343.image_5F00_thumb2_5F00_7A2A1E6F.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image_thumb2" alt="image_thumb2" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/4428.image_thumb2_thumb_1B5A144C.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/4428.image_5F00_thumb2_5F00_thumb_5F00_1B5A144C.png" border="0" height="293" width="720" /></a></p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:418160df-967b-47a1-8782-954cf3e0c960" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">C#</div>
<div style="background: #ddd; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #008000;">// Defines the root URI of the data service.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">readonly</span> <span style="color: #ff0000;">Uri</span> rootUri = <span style="color: #0000ff;">new</span> <span style="color: #ff0000;">Uri</span>(<span style="color: #a31515;">"http://odata.netflix.com/v1/Catalog/"</span>);</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// Define the typed DataServiceContext.</span></li>
<li><span style="color: #0000ff;">private</span> <span style="color: #ff0000;">NetflixCatalog</span> _context;</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #008000;">// Define the binding collection for Titles.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">private</span> <span style="color: #ff0000;">DataServiceCollection</span>&lt;Title&gt; _titles;</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// Gets and sets the collection of Title objects from the feed.</span></li>
<li><span style="color: #0000ff;">public</span> <span style="color: #ff0000;">DataServiceCollection</span>&lt;Title&gt; <span style="color: #ff0000;">Titles</span></li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #ff0000;">get</span> { <span style="color: #0000ff;">return</span> _titles; }</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #0000ff;">private</span> <span style="color: #ff0000;">set</span></li>
<li style="background: #f3f3f3;">{</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// Set the Customers collection.</span></li>
<li>_titles = <span style="color: #ff0000;">value</span>;</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #008000;">// Register a handler for the LoadCompleted callback.</span></li>
<li style="background: #f3f3f3;">_titles.<span style="color: #ff0000;">LoadCompleted</span> += <span style="color: #ff0000;">OnTitlesLoaded</span>;</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// Raise the PropertyChanged events.</span></li>
<li><span style="color: #ff0000;">NotifyPropertyChanged</span>(<span style="color: #a31515;">"Titles"</span>);</li>
<li style="background: #f3f3f3;"></li>
<li>}</li>
<li style="background: #f3f3f3;">}</li>
</ol></div>
</div>
</div>
<p></p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:3442656b-b4de-4986-b6fe-4165486a1a27" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">Visual Basic</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #008000;">' Defines the root URI of the data service.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Private</span> <span style="color: #0000ff;">Shared</span> <span style="color: #0000ff;">ReadOnly</span> rootUri <span style="color: #0000ff;">As</span> <span style="color: #0000ff;">New</span> <span style="color: #2b91af;">Uri</span>(<span style="color: #a31515;">"http://odata.netflix.com/v1/Catalog/"</span>)</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">' Define the typed DataServiceContext.</span></li>
<li><span style="color: #0000ff;">Private</span> _context <span style="color: #0000ff;">As</span> NetflixCatalog</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #008000;">' Define the binding collection for Titles.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Private</span> _titles <span style="color: #0000ff;">As</span> DataServiceCollection(<span style="color: #0000ff;">Of</span> Title)</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">' Gets and sets the collection of Title objects from the feed.</span></li>
<li><span style="color: #0000ff;">Public</span> <span style="color: #0000ff;">Property</span> Titles() <span style="color: #0000ff;">As</span> DataServiceCollection(<span style="color: #0000ff;">Of</span> Title)</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #0000ff;">Get</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Return</span> _titles</li>
<li><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Get</span></li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #0000ff;">Private</span> <span style="color: #0000ff;">Set</span>(value <span style="color: #0000ff;">As</span> DataServiceCollection(<span style="color: #0000ff;">Of</span> Title))</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #008000;">' Set the Customers collection.</span></li>
<li style="background: #f3f3f3;">_titles = value</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">' Register a handler for the LoadCompleted callback.</span></li>
<li>_titles.LoadCompleted += OnTitlesLoaded</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #008000;">' Raise the PropertyChanged events.</span></li>
<li style="background: #f3f3f3;">NotifyPropertyChanged(<span style="color: #a31515;">"Titles"</span>)</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Set</span></li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Property</span></li>
</ol></div>
</div>
</div>
<p>La classe MainViewModel elle-m&ecirc;me est expos&eacute;e en tant que propri&eacute;t&eacute; statique de la classe d'application racine (app), comme montr&eacute;e dans le code suivant:</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:5afa0ea1-8c30-48fc-8d19-5ff57cb7496f" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">C#</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">static</span> <span style="color: #ff0000;">MainViewModel</span> _viewModel = <span style="color: #0000ff;">null</span>;</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #008000;">// A static ViewModel used by the views to bind against.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span></li>
<li><span style="color: #ff0000;">MainViewModel</span></li>
<li style="background: #f3f3f3;">ViewModel</li>
<li>{</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #ff0000;">get</span></li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #008000;">// Delay creation of the view model until we need it.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">if</span> (_viewModel == <span style="color: #0000ff;">null</span>)</li>
<li></li>
<li style="background: #f3f3f3;">{</li>
<li>_viewModel = <span style="color: #0000ff;">new</span> <span style="color: #ff0000;">MainViewModel</span>();</li>
<li style="background: #f3f3f3;">}</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">return</span> _viewModel;</li>
<li>}</li>
<li style="background: #f3f3f3;"></li>
<li>}</li>
</ol></div>
</div>
</div>
<p></p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:a5eef38c-dc67-4785-afa4-2e9cf7fc443e" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">Visual Basic</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">Shared</span> _viewModel <span style="color: #0000ff;">As</span> MainViewModel = <span style="color: #0000ff;">Nothing</span></li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #008000;">' A static ViewModel used by the views to bind against.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Public</span> <span style="color: #0000ff;">Shared</span> <span style="color: #0000ff;">ReadOnly</span> <span style="color: #0000ff;">Property</span> ViewModel() <span style="color: #0000ff;">As</span> MainViewModel</li>
<li><span style="color: #0000ff;">Get</span></li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #008000;">' Delay creation of the view model until we need it.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">If</span> _viewModel <span style="color: #0000ff;">Is</span> <span style="color: #0000ff;">Nothing</span> <span style="color: #0000ff;">Then</span></li>
<li>_viewModel = <span style="color: #0000ff;">New</span> MainViewModel()</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">If</span></li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Return</span> _viewModel</li>
<li><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Get</span></li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Property</span></li>
</ol></div>
</div>
</div>
<p>Le ViewModel est d&eacute;finit sur le DataContext de la page qui nous permet de lier le contr&ocirc;le Listbox &agrave; la DataServiceCollection retourn&eacute;e par la propri&eacute;t&eacute; Titles de la classe MainViewModel. Vous pouvez voir dans l'exemple suivant que la Listbox et quelques autres &eacute;l&eacute;ments sont li&eacute;s aux propri&eacute;t&eacute;s du MainViewModel:</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:613f18aa-a063-46f9-a9c4-e509217a69e2" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">XAML</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">Grid</span><span style="color: #ff0000;"> x</span><span style="color: #0000ff;">:</span><span style="color: #ff0000;">Name</span><span style="color: #0000ff;">="ContentPanel"</span><span style="color: #ff0000;"> Grid.Row</span><span style="color: #0000ff;">="1"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="12,0,12,0"&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">ListBox</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="0,0,-12,0"</span><span style="color: #ff0000;"> ItemsSource</span><span style="color: #0000ff;">="{</span><span style="color: #a31515;">Binding</span><span style="color: #ff0000;"> Titles}</span><span style="color: #0000ff;">"</span></li>
<li><span style="color: #ff0000;">SelectionChanged</span><span style="color: #0000ff;">="</span><span style="color: #ff0000;">OnSelectionChanged</span><span style="color: #0000ff;">"</span><span style="color: #ff0000;"> Height</span><span style="color: #0000ff;">="Auto"&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">ListBox.ItemTemplate</span><span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">DataTemplate</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">StackPanel</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="0,0,0,17"</span><span style="color: #ff0000;"> Width</span><span style="color: #0000ff;">="432"</span><span style="color: #ff0000;"> Orientation</span><span style="color: #0000ff;">="Horizontal"&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">Image</span><span style="color: #ff0000;"> Source</span><span style="color: #0000ff;">="{</span><span style="color: #a31515;">Binding</span><span style="color: #ff0000;"> Path</span><span style="color: #0000ff;">=StreamUri}"</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="75"</span><span style="color: #ff0000;"> Width</span><span style="color: #0000ff;">="50" /&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">StackPanel</span><span style="color: #ff0000;"> Orientation</span><span style="color: #0000ff;">="Vertical"&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">StackPanel.Resources</span><span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #ff0000;">converter</span><span style="color: #0000ff;">:</span><span style="color: #ff0000;">TruncateSynopsis x</span><span style="color: #0000ff;">:</span><span style="color: #ff0000;">Key</span><span style="color: #0000ff;">="synopsis" /&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">StackPanel.Resources</span><span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">TextBlock</span><span style="color: #ff0000;"> Text</span><span style="color: #0000ff;">="{</span><span style="color: #a31515;">Binding</span><span style="color: #ff0000;"> Path</span><span style="color: #0000ff;">=ShortName}"</span><span style="color: #ff0000;"> TextWrapping</span><span style="color: #0000ff;">="Wrap"</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">Style</span><span style="color: #0000ff;">="{</span><span style="color: #a31515;">StaticResource</span><span style="color: #ff0000;"> PhoneTextLargeStyle}</span><span style="color: #0000ff;">"/&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">TextBlock</span><span style="color: #ff0000;"> Text</span><span style="color: #0000ff;">="{</span><span style="color: #a31515;">Binding</span><span style="color: #ff0000;"> Path</span><span style="color: #0000ff;">=ShortSynopsis,</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">Converter</span><span style="color: #0000ff;">={</span><span style="color: #a31515;">StaticResource</span><span style="color: #ff0000;"> synopsis}}</span><span style="color: #0000ff;">"</span></li>
<li><span style="color: #ff0000;">TextWrapping</span><span style="color: #0000ff;">="Wrap"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="12,-6,12,0"</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">Style</span><span style="color: #0000ff;">="{</span><span style="color: #a31515;">StaticResource</span><span style="color: #ff0000;"> PhoneTextSubtleStyle}</span><span style="color: #0000ff;">"/&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">StackPanel</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">StackPanel</span><span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">DataTemplate</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">ListBox.ItemTemplate</span><span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">ListBox</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">Grid</span><span style="color: #0000ff;">&gt;</span></li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">StackPanel</span><span style="color: #ff0000;"> Grid.Row</span><span style="color: #0000ff;">="2"</span><span style="color: #ff0000;"> Orientation</span><span style="color: #0000ff;">="Horizontal"&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">TextBlock</span><span style="color: #ff0000;"> Name</span><span style="color: #0000ff;">="PagingInfo"</span><span style="color: #ff0000;"> Text</span><span style="color: #0000ff;">="{</span><span style="color: #a31515;">Binding</span><span style="color: #ff0000;"> PagesLoadedText}</span><span style="color: #0000ff;">"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="12,20,10,28"</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="270"</span><span style="color: #ff0000;"> Style</span><span style="color: #0000ff;">="{</span><span style="color: #a31515;">StaticResource</span><span style="color: #ff0000;"> PhoneTextNormalStyle}</span><span style="color: #0000ff;">" /&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">Button</span><span style="color: #ff0000;"> Name</span><span style="color: #0000ff;">="MoreButton"</span><span style="color: #ff0000;"> Content</span><span style="color: #0000ff;">="Next Page"</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">HorizontalAlignment</span><span style="color: #0000ff;">="Right"</span><span style="color: #ff0000;"> Width</span><span style="color: #0000ff;">="185"</span><span style="color: #ff0000;"> Height</span><span style="color: #0000ff;">="80"</span><span style="color: #ff0000;"> Click</span><span style="color: #0000ff;">="</span><span style="color: #ff0000;">MoreButton_Click</span><span style="color: #0000ff;">" /&gt;</span></li>
<li><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">StackPanel</span><span style="color: #0000ff;">&gt;</span></li>
</ol></div>
</div>
</div>
<p>Lorsque la page MainPage.xaml se charge, la propri&eacute;t&eacute; IsDataLoaded property de la vue est v&eacute;rifi&eacute;e. Lorsque les donn&eacute;es ne sont pas encore charg&eacute;es, la m&eacute;thode LoadData est appel&eacute;e pour d&eacute;finir le binding, et demande la liste de titre du service de donn&eacute;es.</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6fdc9d1a-a53c-4b44-9f39-daaadf051cbd" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">C#</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #008000;">// Used to determine whether the data is loaded.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">bool</span> IsDataLoaded { <span style="color: #ff0000;">get</span>; <span style="color: #0000ff;">private</span> <span style="color: #ff0000;">set</span>; }</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// Loads data when the application is initialized.</span></li>
<li><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> LoadData()</li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #008000;">// Instantiate the context and binding collection.</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">Context</span> = <span style="color: #0000ff;">new</span> <span style="color: #ff0000;">NetflixCatalog</span>(<span style="color: #ff0000;">_rootUri</span>);</li>
<li><span style="color: #ff0000;">Titles</span> = <span style="color: #0000ff;">new</span> <span style="color: #ff0000;">DataServiceCollection</span>&lt;Title&gt;(<span style="color: #ff0000;">Context</span>);</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #008000;">// Load the data.</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">Titles</span>.LoadAsync(<span style="color: #ff0000;">GetQueryUri</span>());</li>
<li>}</li>
</ol></div>
</div>
</div>
<p></p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:a5dbd12c-062e-4e28-bbd7-c4b5ad36740b" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">Visual Basic</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #008000;">' Used to determine whether the data is loaded.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Public</span> <span style="color: #0000ff;">Property</span> IsDataLoaded() <span style="color: #0000ff;">As</span> <span style="color: #0000ff;">Boolean</span></li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Get</span></li>
<li><span style="color: #0000ff;">Return</span> m_IsDataLoaded</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Get</span></li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Private</span> <span style="color: #0000ff;">Set</span>(value <span style="color: #0000ff;">As</span> <span style="color: #0000ff;">Boolean</span>)</li>
<li>m_IsDataLoaded = Value</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Set</span></li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Property</span></li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Private</span> m_IsDataLoaded <span style="color: #0000ff;">As</span> <span style="color: #0000ff;">Boolean</span></li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">' Loads data when the application is initialized.</span></li>
<li><span style="color: #0000ff;">Public</span> <span style="color: #0000ff;">Sub</span> LoadData()</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #008000;">' Instantiate the context and binding collection.</span></li>
<li style="background: #f3f3f3;">Context = <span style="color: #0000ff;">New</span> NetflixCatalog(_rootUri)</li>
<li>Titles = <span style="color: #0000ff;">New</span> DataServiceCollection(<span style="color: #0000ff;">Of</span> Title)(Context)</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #008000;">' Load the data.</span></li>
<li style="background: #f3f3f3;">Titles.LoadAsync(GetQueryUri())</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Sub</span></li>
</ol></div>
</div>
</div>
<p>Lorsque la m&eacute;thode LoadAsync est appel&eacute;e, la biblioth&egrave;que client envoie une requ&ecirc;te asynchrone au service OData qui retourne un flux Atom des entr&eacute;es Titles. Lorsque la r&eacute;ponse est re&ccedil;ue, l'&eacute;v&egrave;nement LoadCompleted est d&eacute;clench&eacute; et les entr&eacute;es dans le flux sont mat&eacute;rialis&eacute;es par le client dans des objets dans la collection de Titles, qui est li&eacute;e au contr&ocirc;le ListBox.</p>
<p>OData d&eacute;finit un m&eacute;canisme pour acc&eacute;der aux donn&eacute;es binaires s&eacute;par&eacute;ment de l'entit&eacute; &agrave; laquelle elles appartiennent. De cette fa&ccedil;on, un service de donn&eacute;es peut exposer de nombreuses donn&eacute;es binaires en tant que ressources m&eacute;dia qui appartiennent &agrave; une entr&eacute;e de lien m&eacute;dia. Dans le catalogue Netflix, l'entit&eacute; Title est une entr&eacute;e de lien m&eacute;dia avec une ressource m&eacute;dia li&eacute;e, qui est la couverture du titre. La m&eacute;thode GetReadStreamUri du viewmodel appelle la m&eacute;thode GetReadStreamUri sur le DataServiceContext pour retourner l'URI de la ressource m&eacute;dia.</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6cd9118b-7c4c-477e-95a5-e24fd9727e1f" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">C#</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #008000;">// Extend the Title class to bind to the media resource URI.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">public</span> <span style="color: #ff0000;">partial</span> <span style="color: #0000ff;">class</span> <span style="color: #2b91af;">Title</span></li>
<li>{</li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// Returns the media resource URI for binding.</span></li>
<li><span style="color: #0000ff;">public</span> <span style="color: #ff0000;">Uri</span> <span style="color: #ff0000;">StreamUri</span></li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #ff0000;">get</span></li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #008000;">// Get the URI for the media resource stream.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">return</span> <span style="color: #2b91af;">App</span>.<span style="color: #ff0000;">ViewModel</span>.GetReadStreamUri(<span style="color: #0000ff;">this</span>);</li>
<li>}</li>
<li style="background: #f3f3f3;">}</li>
<li>}</li>
</ol></div>
</div>
</div>
<p></p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e03ef93b-a664-4252-a869-51b4cfb0c54c" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">Visual Basic</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #008000;">' Extend the Title class to bind to the media resource URI.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Partial</span> <span style="color: #0000ff;">Public</span> <span style="color: #0000ff;">Class</span> <span style="color: #2b91af;">Title</span></li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">' Returns the media resource URI for binding.</span></li>
<li><span style="color: #0000ff;">Public</span> <span style="color: #0000ff;">ReadOnly</span> <span style="color: #0000ff;">Property</span> StreamUri() <span style="color: #0000ff;">As</span> <span style="color: #2b91af;">Uri</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Get</span></li>
<li><span style="color: #008000;">' Get the URI for the media resource stream.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Return</span> <span style="color: #ff0000;">App</span>.ViewModel.GetReadStreamUri(<span style="color: #0000ff;">Me</span>)</li>
<li><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Get</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Property</span></li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Class</span></li>
</ol></div>
</div>
</div>
<p>Dans cet exemple, la propri&eacute;t&eacute; StreamUri appelle la m&eacute;thode GetReadStreamUri pour retourner l'URI de ressource qui est une image de couverture. Lorsque nous lions la propri&eacute;t&eacute; StreamURI &agrave; l'attribut Source d'un contr&ocirc;le Image, l'URI retourn&eacute;e est utilis&eacute;e pour t&eacute;l&eacute;charger et afficher la couverture pour chaque titre.</p>
<h5>Recommandation</h5>
<p>Pour une entr&eacute;e de lien m&eacute;dia, nous recommandons que vous obteniez l'URI de la ressource en appelant la m&eacute;thode GetReadStreamUri() plut&ocirc;t qu'une autre propri&eacute;t&eacute; de l'entit&eacute;. Bien que l'URI de la ressource m&eacute;dia marche bien dans ce cas pour cr&eacute;er une image sur le client, d'autres m&eacute;thodes du DataServiceContext peuvent &ecirc;tre utilis&eacute;es pour acc&eacute;der et changer les ressources m&eacute;dia en tant que stream binaire.</p>
<p></p>
<h2><a name="PagingNavigation"></a>Paging et Navigation</h2>
<p>Dans cet exemple, l'URI de requ&ecirc;te est construite en utilisant les param&egrave;tres de pagination d&eacute;finis dans l'application. Dans OData, il existe deux sortes de paging. Un client peut utiliser les options de requ&ecirc;te $top et $skip pour limiter le nombre d'entr&eacute;es dans la r&eacute;ponse dans une page logique plut&ocirc;t que l'ensemble des donn&eacute;es. Le service de donn&eacute;es lui-m&ecirc;me peut aussi limiter le nombre d'entr&eacute;es retourn&eacute;es par une r&eacute;ponse donn&eacute;e, lorsque la r&eacute;ponse contient un token (jeton) de continuation qui est utilis&eacute; pour obtenir la page suivante de donn&eacute;es &agrave; partir du service de donn&eacute;es.</p>
<p>Parce que le client n'est pas capable de d&eacute;terminer si un service de donn&eacute;es impl&eacute;mente un paging pilot&eacute; par le serveur ou simplement la taille d'une page, vous devriez consid&eacute;rer &agrave; impl&eacute;menter un paging c&ocirc;t&eacute; client dans vos applications Windows Phone pour s'assurer qu'aucune requ&ecirc;te ne retourne un trop gros ensemble de donn&eacute;es, ce qui prendrait du temps et consommerait les ressources du t&eacute;l&eacute;phone. Vous devriez aussi &ecirc;tre pr&eacute;par&eacute; &agrave; prendre en compte du paging c&ocirc;t&eacute; serveur dans votre application.</p>
<p>L'exemple suivant montre la m&eacute;thode GetQueryUri() qui retourne l'URI de requ&ecirc;te, qui est cr&eacute;&eacute;e en se basant sur les variables pass&eacute;es aux param&egrave;tres $top et $skip.</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:2c293c01-6f7b-4657-87f2-d49bc8e44a22" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">C#</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #008000;">// Private method that returns the page-specific query.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">private</span> <span style="color: #ff0000;">Uri</span> GetQueryUri()</li>
<li>{</li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// Construct and return the query URI for the next page of results.</span></li>
<li><span style="color: #0000ff;">var</span> queryUri = <span style="color: #0000ff;">new</span> <span style="color: #ff0000;">Uri</span>(<span style="color: #0000ff;">string</span>.Format(<span style="color: #a31515;">"/Titles?$top={0}&amp;$skip={1}"</span>,</li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">_pageSize</span>, <span style="color: #ff0000;">_currentPage</span> * <span style="color: #ff0000;">_pageSize</span>), <span style="color: #ff0000;">UriKind</span>.Relative);</li>
<li><span style="color: #0000ff;">if</span> (<span style="color: #ff0000;">_currentPage</span> == 0)</li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #008000;">// If this is the first page, then also include a count of all titles.</span></li>
<li style="background: #f3f3f3;">queryUri = <span style="color: #0000ff;">new</span> <span style="color: #ff0000;">Uri</span>(queryUri.<span style="color: #ff0000;">ToString</span>() +</li>
<li><span style="color: #a31515;">"&amp;$inlinecount=allpages"</span>, <span style="color: #ff0000;">UriKind</span>.Relative);</li>
<li style="background: #f3f3f3;">}</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">return</span> queryUri;</li>
<li>}</li>
</ol></div>
</div>
</div>
<p></p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e48e7f66-ba62-479b-9c7f-fe95b08fbb72" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">Visual Basic</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #008000;">' Private method that returns the page-specific query.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Private</span> <span style="color: #0000ff;">Function</span> GetQueryUri() <span style="color: #0000ff;">As</span> <span style="color: #2b91af;">Uri</span></li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">' Construct and return the query URI for the next page of results.</span></li>
<li><span style="color: #0000ff;">Dim</span> queryUri = <span style="color: #0000ff;">New</span> <span style="color: #2b91af;">Uri</span>(<span style="color: #0000ff;">String</span>.Format(<span style="color: #a31515;">"/Titles?$top={0}&amp;$skip={1}"</span>, _pageSize, _currentPage * _pageSize), <span style="color: #2b91af;">UriKind</span>.Relative)</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #0000ff;">If</span> _currentPage = 0 <span style="color: #0000ff;">Then</span></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">' If this is the first page, then also include a count of all titles.</span></li>
<li>queryUri = <span style="color: #0000ff;">New</span> <span style="color: #2b91af;">Uri</span>(queryUri.ToString() &amp; <span style="color: #a31515;">"&amp;$inlinecount=allpages"</span>, <span style="color: #2b91af;">UriKind</span>.Relative)</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">If</span></li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Return</span> queryUri</li>
<li><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Function</span></li>
</ol></div>
</div>
</div>
<p>Dans cet exemple, la taille de page est fixe et le nombre d'entr&eacute;e &agrave; sauter est calcul&eacute; en fonction du nombre de la page courante. Lorsque nous chargeons la premi&egrave;re page, nous incluons l'option de requ&ecirc;te $inlinecount=allpages pour demander le compte total de toutes les entit&eacute;s Titles, qui est utilis&eacute;e pour calculer le nombre de pages qui est affich&eacute; dans TitlesPage.xaml.</p>
<p>Lorsque la r&eacute;ponse est re&ccedil;ue, le client d&eacute;clenche l'&eacute;v&egrave;nement <i>LoadCompleted</i>. Lorsqu'il est n&eacute;cessaire de charger des pages suppl&eacute;mentaires &agrave; cause du paging c&ocirc;t&eacute; serveur, la propri&eacute;t&eacute; Continuation de l'objet DataServiceCollection retourne un token(jeton) de continuation. La m&eacute;thode suivante g&egrave;re l'&eacute;v&egrave;nement LoadCompleted pour charger les pages:</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6d522874-4248-4b38-a6d9-be7b3531fe31" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">C#</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> OnTitlesLoaded(<span style="color: #0000ff;">object</span> sender, <span style="color: #ff0000;">LoadCompletedEventArgs</span> e)</li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #008000;">// Make sure that we load all pages of the Customers feed.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">if</span> (<span style="color: #ff0000;">Titles</span>.Continuation != <span style="color: #0000ff;">null</span>)</li>
<li>{</li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">Titles</span>.LoadNextPartialSetAsync();</li>
<li>}</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #008000;">// Set the total page count, if we requested one.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">if</span> (<span style="color: #ff0000;">e</span>.QueryOperationResponse.Query</li>
<li>.RequestUri.Query.Contains(<span style="color: #a31515;">"$inlinecount=allpages"</span>))</li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #ff0000;">_totalCount</span> = (<span style="color: #0000ff;">int</span>)<span style="color: #ff0000;">e</span>.QueryOperationResponse.TotalCount;</li>
<li style="background: #f3f3f3;">}</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">IsDataLoaded</span> = <span style="color: #0000ff;">true</span>;</li>
<li><span style="color: #008000;">// Update the pages loaded text binding.</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">NotifyPropertyChanged</span>(<span style="color: #a31515;">"PagesLoadedText"</span>);</li>
<li>}</li>
</ol></div>
</div>
</div>
<p></p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:efe268a9-61f1-46e0-8b17-61a3d90be9b9" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">Visual Basic</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">Private</span> <span style="color: #0000ff;">Sub</span> OnTitlesLoaded(sender <span style="color: #0000ff;">As</span> <span style="color: #0000ff;">Object</span>, e <span style="color: #0000ff;">As</span> LoadCompletedEventArgs)</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #008000;">' Make sure that we load all pages of the Customers feed.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">If</span> Titles.Continuation <span style="color: #0000ff;">IsNot</span> <span style="color: #0000ff;">Nothing</span> <span style="color: #0000ff;">Then</span></li>
<li>Titles.LoadNextPartialSetAsync()</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">If</span></li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">' Set the total page count, if we requested one.</span></li>
<li><span style="color: #0000ff;">If</span> e.QueryOperationResponse.Query.RequestUri.Query.Contains(<span style="color: #a31515;">"$inlinecount=allpages"</span>) <span style="color: #0000ff;">Then</span></li>
<li style="background: #f3f3f3;">_totalCount = <span style="color: #0000ff;">CInt</span>(e.QueryOperationResponse.TotalCount)</li>
<li><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">If</span></li>
<li style="background: #f3f3f3;"></li>
<li>IsDataLoaded = <span style="color: #0000ff;">True</span></li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #008000;">' Update the pages loaded text binding.</span></li>
<li style="background: #f3f3f3;">NotifyPropertyChanged(<span style="color: #a31515;">"PagesLoadedText"</span>)</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Sub</span></li>
</ol></div>
</div>
</div>
<p>Notez que nous lisons aussi et enregistrons la valeur TotalCount lorsque celle-ci est demand&eacute;e dans la requ&ecirc;te. Cette valeur est utilis&eacute;e pour calculer et afficher le nombre total de pages. Parce qu'une version de TotalCount mise &agrave; jour change la valeur de la propri&eacute;t&eacute; PagesLoadedText, nous reportons aussi ce changement jusqu'au binding.</p>
<p>La page de donn&eacute;es suivante est demand&eacute;e lorsque l'utilisateur appuie sur le bouton <i>Next Page.</i> Vous pourriez cr&eacute;er un nouvel objet DataServiceCollection bas&eacute; sur l'URI qui retourne la page suivant, l'exemple suivant utilise au contraire la navigation pour charger une page sp&eacute;cifique de donn&eacute;es:</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1eec0be9-7931-4773-9eaf-007b7fc92da1" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">Code Snippet</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> MoreButton_Click(<span style="color: #0000ff;">object</span> sender, <span style="color: #ff0000;">RoutedEventArgs</span> e)</li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #0000ff;">if</span> (<span style="color: #2b91af;">App</span>.<span style="color: #ff0000;">ViewModel</span>.IsDataLoaded)</li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #008000;">// Navigate to the next page of data.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">this</span>.NavigationService.Navigate(</li>
<li><span style="color: #0000ff;">new</span> <span style="color: #2b91af;">Uri</span>(<span style="color: #a31515;">"/TitlesPage.xaml?page="</span></li>
<li style="background: #f3f3f3;">+ (<span style="color: #2b91af;">App</span>.<span style="color: #ff0000;">ViewModel</span>.CurrentPage + 1), <span style="color: #2b91af;">UriKind</span>.Relative));</li>
<li>}</li>
<li style="background: #f3f3f3;">}</li>
</ol></div>
</div>
</div>
<p></p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:470d3649-e7c4-42b0-afd7-bfff828f2b30" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">Visual Basic</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">Private</span> <span style="color: #0000ff;">Sub</span> MoreButton_Click(sender <span style="color: #0000ff;">As</span> <span style="color: #0000ff;">Object</span>, e <span style="color: #0000ff;">As</span> RoutedEventArgs)</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">If</span> App.ViewModel.IsDataLoaded <span style="color: #0000ff;">Then</span></li>
<li><span style="color: #008000;">' Navigate to the next page of data.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Me</span>.NavigationService.Navigate(<span style="color: #0000ff;">New</span> <span style="color: #2b91af;">Uri</span>(<span style="color: #a31515;">"/TitlesPage.xaml?page="</span> &amp; (App.ViewModel.CurrentPage + 1), <span style="color: #2b91af;">UriKind</span>.Relative))</li>
<li><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">If</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Sub</span></li>
</ol></div>
</div>
</div>
<p>Cette navigation recharge principalement la page MainPage.xaml avec la page suivante.</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:03983dd0-e452-46e8-b721-a8b23a8ec471" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">C#</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span> OnNavigatedTo(<span style="color: #ff0000;">NavigationEventArgs</span> <span style="color: #ff0000;">e</span>)</li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #0000ff;">if</span> (!<span style="color: #2b91af;">App</span>.<span style="color: #ff0000;">ViewModel</span>.IsDataLoaded)</li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #2b91af;">App</span>.<span style="color: #ff0000;">ViewModel</span>.LoadData();</li>
<li style="background: #f3f3f3;">}</li>
<li><span style="color: #0000ff;">else</span></li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">this</span>.NavigationContext.QueryString.Count == 1)</li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #008000;">// Get the value of the requested page.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">int</span> page = <span style="color: #0000ff;">int</span>.Parse(<span style="color: #0000ff;">this</span>.NavigationContext.QueryString[<span style="color: #a31515;">"page"</span>]);</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// Check to see if the page is currently loaded.</span></li>
<li><span style="color: #0000ff;">if</span> (page != <span style="color: #2b91af;">App</span>.<span style="color: #ff0000;">ViewModel</span>.CurrentPage)</li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #008000;">// Load data for the specific page.</span></li>
<li style="background: #f3f3f3;"><span style="color: #2b91af;">App</span>.<span style="color: #ff0000;">ViewModel</span>.LoadData(page);</li>
<li>}</li>
<li style="background: #f3f3f3;"></li>
<li>}</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">else</span></li>
<li>{</li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// If there is no query parameter, we are at the first page.</span></li>
<li><span style="color: #2b91af;">App</span>.<span style="color: #ff0000;">ViewModel</span>.LoadData(0);</li>
<li style="background: #f3f3f3;">}</li>
<li>}</li>
<li style="background: #f3f3f3;">}</li>
</ol></div>
</div>
</div>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:ddcc7b4e-4aa0-4a8f-a144-e29af7637503" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">Visual Basic</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">Protected</span> <span style="color: #0000ff;">Overrides</span> <span style="color: #0000ff;">Sub</span> OnNavigatedTo(e <span style="color: #0000ff;">As</span> NavigationEventArgs)</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #0000ff;">If</span> <span style="color: #0000ff;">Not</span> App.ViewModel.IsDataLoaded <span style="color: #0000ff;">Then</span></li>
<li style="background: #f3f3f3;">App.ViewModel.LoadData()</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Else</span></li>
<li><span style="color: #0000ff;">If</span> <span style="color: #0000ff;">Me</span>.NavigationContext.QueryString.Count = 1 <span style="color: #0000ff;">Then</span></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">' Get the value of the requested page.</span></li>
<li><span style="color: #0000ff;">Dim</span> page <span style="color: #0000ff;">As</span> <span style="color: #0000ff;">Integer</span> = <span style="color: #0000ff;">Integer</span>.Parse(<span style="color: #0000ff;">Me</span>.NavigationContext.QueryString(<span style="color: #a31515;">"page"</span>))</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #008000;">' Check to see if the page is currently loaded.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">If</span> page &lt;&gt; App.ViewModel.CurrentPage <span style="color: #0000ff;">Then</span></li>
<li><span style="color: #008000;">' Load data for the specific page.</span></li>
<li style="background: #f3f3f3;">App.ViewModel.LoadData(page)</li>
<li><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">If</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Else</span></li>
<li><span style="color: #008000;">' If there is no query parameter, we are at the first page.</span></li>
<li style="background: #f3f3f3;">App.ViewModel.LoadData(0)</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">If</span></li>
<li><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">If</span></li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Sub</span></li>
</ol></div>
</div>
</div>
<p>En utilisant la navigation pour charger les pages suivantes, lorsque l'utilisateur clique sur le bouton Retour, le comportement par d&eacute;faut est de recharger la page pr&eacute;c&eacute;dente. Sans la navigation, vous auriez besoin de surcharger la m&eacute;thode OnBackKeyPress pour charger la page pr&eacute;c&eacute;dente.</p>
<p>Lorsque l'utilisateur clique sur un titre dans le contr&ocirc;le ListBox, la m&eacute;thode suivante navigue vers la page TitlesDetailPage.xaml pour le titre s&eacute;lectionn&eacute; :</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:bbc410ec-cb75-4afb-9573-b2bb1c62ccbc" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">C#</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> OnSelectionChanged(<span style="color: #0000ff;">object</span> sender, <span style="color: #ff0000;">SelectionChangedEventArgs</span> e)</li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #0000ff;">var</span> selector = (<span style="color: #ff0000;">Selector</span>)<span style="color: #ff0000;">sender</span>;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">if</span> (selector.<span style="color: #ff0000;">SelectedIndex</span> == -1)</li>
<li>{</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">return</span>;</li>
<li>}</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #0000ff;">this</span>.NavigationService.Navigate(</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">new</span> <span style="color: #2b91af;">Uri</span>(<span style="color: #a31515;">"/TitleDetailsPage.xaml?selectedIndex="</span></li>
<li>+ selector.<span style="color: #ff0000;">SelectedIndex</span>, <span style="color: #2b91af;">UriKind</span>.Relative));</li>
<li style="background: #f3f3f3;">selector.<span style="color: #ff0000;">SelectedIndex</span> = -1;</li>
<li>}</li>
</ol></div>
</div>
</div>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6853d972-3349-42dd-815b-781e29c88512" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">Visual Basic</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">Private</span> <span style="color: #0000ff;">Sub</span> OnSelectionChanged(sender <span style="color: #0000ff;">As</span> <span style="color: #0000ff;">Object</span>, e <span style="color: #0000ff;">As</span> SelectionChangedEventArgs)</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Dim</span> selector = <span style="color: #0000ff;">DirectCast</span>(sender, Selector)</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">If</span> selector.SelectedIndex = -1 <span style="color: #0000ff;">Then</span></li>
<li><span style="color: #0000ff;">Return</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">If</span></li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Me</span>.NavigationService.Navigate(<span style="color: #0000ff;">New</span> <span style="color: #2b91af;">Uri</span>(<span style="color: #a31515;">"/TitleDetailsPage.xaml?selectedIndex="</span> &amp; <span style="color: #2b91af;">Convert</span>.ToString(selector.SelectedIndex), <span style="color: #2b91af;">UriKind</span>.Relative))</li>
<li>selector.SelectedIndex = -1</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Sub</span></li>
</ol></div>
</div>
</div>
<p>Dans la page TitleDetailsPage.xaml, la valeur de l'index s&eacute;lectionn&eacute; est utilis&eacute;e pour lier le bon Title depuis la collection de Titles, comme ceci :</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:fb0ab152-daf1-403f-9d0d-a9694a0777d9" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">C#</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span> OnNavigatedTo(<span style="color: #ff0000;">NavigationEventArgs</span> <span style="color: #ff0000;">e</span>)</li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #0000ff;">string</span> indexAsString = <span style="color: #0000ff;">this</span>.NavigationContext.QueryString[<span style="color: #a31515;">"selectedIndex"</span>];</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">int</span> index = <span style="color: #0000ff;">int</span>.Parse(indexAsString);</li>
<li><span style="color: #0000ff;">this</span>.DataContext = <span style="color: #0000ff;">this</span>.<span style="color: #ff0000;">currentTitle</span></li>
<li style="background: #f3f3f3;">= (Title)<span style="color: #2b91af;">App</span>.<span style="color: #ff0000;">ViewModel</span>.Titles[index];</li>
<li>}</li>
</ol></div>
</div>
</div>
<p></p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:630b9913-8bc6-47e3-b804-9ef5a425bc60" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">Visual Basic</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">Protected</span> <span style="color: #0000ff;">Overrides</span> <span style="color: #0000ff;">Sub</span> OnNavigatedTo(e <span style="color: #0000ff;">As</span> NavigationEventArgs)</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Dim</span> indexAsString <span style="color: #0000ff;">As</span> <span style="color: #0000ff;">String</span> = <span style="color: #0000ff;">Me</span>.NavigationContext.QueryString(<span style="color: #a31515;">"selectedIndex"</span>)</li>
<li><span style="color: #0000ff;">Dim</span> index <span style="color: #0000ff;">As</span> <span style="color: #0000ff;">Integer</span> = <span style="color: #0000ff;">Integer</span>.Parse(indexAsString)</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Me</span>.DataContext = InlineAssignHelper(<span style="color: #0000ff;">Me</span>.currentTitle, <span style="color: #0000ff;">DirectCast</span>(App.ViewModel.Titles(index), Title))</li>
<li><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Sub</span></li>
</ol></div>
</div>
</div>
<p></p>
<h2><a name="MaintainingState"></a>Maintenir l'&eacute;tat d'application</h2>
<p>Le syst&egrave;me d'exploitation Windows Phone permet seulement &agrave; une seule application de s'ex&eacute;cuter &agrave; un moment donn&eacute;. Lorsque l'utilisateur quitte une application, le syst&egrave;me &eacute;teint cette application. Pour permettre &agrave; l'application d'&ecirc;tre r&eacute;activ&eacute;e correctement, les donn&eacute;es charg&eacute;es, les informations d'&eacute;tat des objets et certaines propri&eacute;t&eacute;s du ViewModel doivent &ecirc;tre stock&eacute;es dans le dictionnaire d'&eacute;tat. Le client OData pour Windows Phone 7 introduit une classe DataServiceState qui est utilis&eacute;e pour stocker le DataServiceContext et une collection d'objets DataServiceCollection. La m&eacute;thode suivante SaveState dans le ViewModel retourne cet objet DataServiceState dans une collection cl&eacute;-valeur d'&eacute;l&eacute;ments, ainsi que d'autres donn&eacute;es du ViewModel qui doivent &ecirc;tre persist&eacute;es:</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:98ba686c-4807-44de-851f-d0ef8e68c470" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">C#</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #008000;">// Return a collection of key-value pairs to store in the application state.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">public</span> <span style="color: #2b91af;">List</span>&lt;<span style="color: #2b91af;">KeyValuePair</span>&lt;<span style="color: #0000ff;">string</span>, <span style="color: #0000ff;">object</span>&gt;&gt; SaveState()</li>
<li>{</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">if</span> (<span style="color: #2b91af;">App</span>.<span style="color: #ff0000;">ViewModel</span>.IsDataLoaded)</li>
<li>{</li>
<li style="background: #f3f3f3;"><span style="color: #2b91af;">List</span>&lt;<span style="color: #2b91af;">KeyValuePair</span>&lt;<span style="color: #0000ff;">string</span>, <span style="color: #0000ff;">object</span>&gt;&gt; stateList</li>
<li>= <span style="color: #0000ff;">new</span> <span style="color: #2b91af;">List</span>&lt;<span style="color: #2b91af;">KeyValuePair</span>&lt;<span style="color: #0000ff;">string</span>, <span style="color: #0000ff;">object</span>&gt;&gt;();</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #008000;">// Create a new dictionary to store binding collections.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">var</span> collections = <span style="color: #0000ff;">new</span> <span style="color: #2b91af;">Dictionary</span>&lt;<span style="color: #0000ff;">string</span>, <span style="color: #0000ff;">object</span>&gt;();</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// Add the current Titles binding collection.</span></li>
<li>collections[<span style="color: #a31515;">"Titles"</span>] = <span style="color: #2b91af;">App</span>.<span style="color: #ff0000;">ViewModel</span>.Titles;</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #008000;">// Store the current context and binding collections in the view model state.</span></li>
<li style="background: #f3f3f3;">stateList.Add(<span style="color: #0000ff;">new</span> <span style="color: #2b91af;">KeyValuePair</span>&lt;<span style="color: #0000ff;">string</span>, <span style="color: #0000ff;">object</span>&gt;(</li>
<li><span style="color: #a31515;">"DataServiceState"</span>, <span style="color: #ff0000;">DataServiceState</span>.Save(<span style="color: #ff0000;">_context</span>, collections)));</li>
<li style="background: #f3f3f3;">stateList.Add(<span style="color: #0000ff;">new</span> <span style="color: #2b91af;">KeyValuePair</span>&lt;<span style="color: #0000ff;">string</span>, <span style="color: #0000ff;">object</span>&gt;(<span style="color: #a31515;">"CurrentPage"</span>, <span style="color: #ff0000;">CurrentPage</span>));</li>
<li>stateList.Add(<span style="color: #0000ff;">new</span> <span style="color: #2b91af;">KeyValuePair</span>&lt;<span style="color: #0000ff;">string</span>, <span style="color: #0000ff;">object</span>&gt;(<span style="color: #a31515;">"TotalCount"</span>, <span style="color: #ff0000;">TotalCount</span>));</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #0000ff;">return</span> stateList;</li>
<li style="background: #f3f3f3;">}</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">else</span></li>
<li>{</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">null</span>;</li>
<li>}</li>
<li style="background: #f3f3f3;">}</li>
</ol></div>
</div>
</div>
<p></p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:7a2d7d41-85ca-46cc-ad09-eed896d1cc8f" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">Visual Basic</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #008000;">' Return a collection of key-value pairs to store in the application state.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Public</span> <span style="color: #0000ff;">Function</span> SaveState() <span style="color: #0000ff;">As</span> <span style="color: #2b91af;">List</span>(<span style="color: #0000ff;">Of</span> <span style="color: #2b91af;">KeyValuePair</span>(<span style="color: #0000ff;">Of</span> <span style="color: #0000ff;">String</span>, <span style="color: #0000ff;">Object</span>))</li>
<li><span style="color: #0000ff;">If</span> App.ViewModel.IsDataLoaded <span style="color: #0000ff;">Then</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Dim</span> stateList <span style="color: #0000ff;">As</span> <span style="color: #0000ff;">New</span> <span style="color: #2b91af;">List</span>(<span style="color: #0000ff;">Of</span> <span style="color: #2b91af;">KeyValuePair</span>(<span style="color: #0000ff;">Of</span> <span style="color: #0000ff;">String</span>, <span style="color: #0000ff;">Object</span>))()</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">' Create a new dictionary to store binding collections.</span></li>
<li><span style="color: #0000ff;">Dim</span> collections = <span style="color: #0000ff;">New</span> <span style="color: #2b91af;">Dictionary</span>(<span style="color: #0000ff;">Of</span> <span style="color: #0000ff;">String</span>, <span style="color: #0000ff;">Object</span>)()</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #008000;">' Add the current Titles binding collection.</span></li>
<li style="background: #f3f3f3;">collections(<span style="color: #a31515;">"Titles"</span>) = App.ViewModel.Titles</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">' Store the current context and binding collections in the view model state.</span></li>
<li>stateList.Add(<span style="color: #0000ff;">New</span> <span style="color: #2b91af;">KeyValuePair</span>(<span style="color: #0000ff;">Of</span> <span style="color: #0000ff;">String</span>, <span style="color: #0000ff;">Object</span>)(<span style="color: #a31515;">"DataServiceState"</span>, DataServiceState.Save(_context, collections)))</li>
<li style="background: #f3f3f3;">stateList.Add(<span style="color: #0000ff;">New</span> <span style="color: #2b91af;">KeyValuePair</span>(<span style="color: #0000ff;">Of</span> <span style="color: #0000ff;">String</span>, <span style="color: #0000ff;">Object</span>)(<span style="color: #a31515;">"CurrentPage"</span>, CurrentPage))</li>
<li>stateList.Add(<span style="color: #0000ff;">New</span> <span style="color: #2b91af;">KeyValuePair</span>(<span style="color: #0000ff;">Of</span> <span style="color: #0000ff;">String</span>, <span style="color: #0000ff;">Object</span>)(<span style="color: #a31515;">"TotalCount"</span>, TotalCount))</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #0000ff;">Return</span> stateList</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Else</span></li>
<li><span style="color: #0000ff;">Return</span> <span style="color: #0000ff;">Nothing</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">If</span></li>
<li><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Function</span></li>
</ol></div>
</div>
</div>
<p>La m&eacute;thode suivante g&egrave;re l'&eacute;v&egrave;nement Deactivated et appelle la m&eacute;thode SaveState pour stocker les donn&eacute;es du viewmodel lorsque l'application est d&eacute;sactiv&eacute;e:</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:487ba497-78d2-47ec-a044-7347f70c2458" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">C#</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #008000;">// Code to execute when the application is deactivated (sent to background).</span></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// This code will not execute when the application is closing.</span></li>
<li><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> Application_Deactivated(<span style="color: #0000ff;">object</span> sender, <span style="color: #ff0000;">DeactivatedEventArgs</span> e)</li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #0000ff;">if</span> (<span style="color: #2b91af;">App</span>.<span style="color: #ff0000;">ViewModel</span>.IsDataLoaded)</li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #008000;">// Store each key-value pair in the state dictionary.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">foreach</span> (<span style="color: #ff0000;">KeyValuePair</span>&lt;<span style="color: #0000ff;">string</span>, <span style="color: #0000ff;">object</span>&gt; item <span style="color: #0000ff;">in</span> <span style="color: #2b91af;">App</span>.<span style="color: #ff0000;">ViewModel</span>.SaveState())</li>
<li>{</li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">PhoneApplicationService</span>.Current.State[item.<span style="color: #ff0000;">Key</span>] = item.<span style="color: #ff0000;">Value</span>;</li>
<li>}</li>
<li style="background: #f3f3f3;">}</li>
<li>}</li>
</ol></div>
</div>
</div>
<p></p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1c52b006-ae14-4634-8cc0-601a04888a0d" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">Visual Basic</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #008000;">' Code to execute when the application is deactivated (sent to background).</span></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">' This code will not execute when the application is closing.</span></li>
<li><span style="color: #0000ff;">Private</span> <span style="color: #0000ff;">Sub</span> Application_Deactivated(sender <span style="color: #0000ff;">As</span> <span style="color: #0000ff;">Object</span>, e <span style="color: #0000ff;">As</span> DeactivatedEventArgs)</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">If</span> App.ViewModel.IsDataLoaded <span style="color: #0000ff;">Then</span></li>
<li><span style="color: #008000;">' Store each key-value pair in the state dictionary.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">For</span> <span style="color: #0000ff;">Each</span> item <span style="color: #0000ff;">As</span> <span style="color: #2b91af;">KeyValuePair</span>(<span style="color: #0000ff;">Of</span> <span style="color: #0000ff;">String</span>, <span style="color: #0000ff;">Object</span>) <span style="color: #0000ff;">In</span> App.ViewModel.SaveState()</li>
<li>PhoneApplicationService.Current.State(item.Key) = item.Value</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Next</span></li>
<li><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">If</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Sub</span></li>
</ol></div>
</div>
</div>
<p>Lorsque l'application est r&eacute;activ&eacute;e, le ViewModel est r&eacute;cup&eacute;r&eacute; depuis le dictionnaire d'&eacute;tat. La m&eacute;thode suivante g&egrave;re l'&eacute;v&egrave;nement Activated et restaure l'application dans son ancien &eacute;tat:</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:16e4fa1c-9921-47cd-b060-4608500fe9c7" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">C#</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #008000;">// Code to execute when the application is activated (brought to foreground).</span></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// This code will not execute when the application is first launched.</span></li>
<li><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> Application_Activated(<span style="color: #0000ff;">object</span> sender, <span style="color: #ff0000;">ActivatedEventArgs</span> e)</li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #2b91af;">App</span>.<span style="color: #ff0000;">ViewModel</span>.RestoreState(<span style="color: #ff0000;">PhoneApplicationService</span>.Current.State);</li>
<li style="background: #f3f3f3;">}</li>
</ol></div>
</div>
</div>
<p></p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1e3c28a0-f8b6-4460-a007-e83dfd41d438" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">Visual Basic</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #008000;">' Code to execute when the application is activated (brought to foreground).</span></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">' This code will not execute when the application is first launched.</span></li>
<li><span style="color: #0000ff;">Private</span> <span style="color: #0000ff;">Sub</span> Application_Activated(sender <span style="color: #0000ff;">As</span> <span style="color: #0000ff;">Object</span>, e <span style="color: #0000ff;">As</span> ActivatedEventArgs)</li>
<li style="background: #f3f3f3;">App.ViewModel.RestoreState(PhoneApplicationService.Current.State)</li>
<li><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Sub</span></li>
</ol></div>
</div>
</div>
<p>Dans la m&eacute;thode RestoreState suivante, l'objet DataServiceState et les autres donn&eacute;es enregistr&eacute;es sont acquises depuis le dictionnaire d'&eacute;tat global et utilis&eacute;es pour r&eacute;initialiser le viewmodel:</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:cdc0a7fa-cd06-4da6-9a9f-ef25bb65d4ef" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">C#</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #008000;">// Restores the view model state from the supplied state dictionary.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> RestoreState(<span style="color: #ff0000;">IDictionary</span>&lt;<span style="color: #0000ff;">string</span>, <span style="color: #0000ff;">object</span>&gt; <span style="color: #ff0000;">dictionary</span>)</li>
<li>{</li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// Create a dictionary to hold any stored binding collections.</span></li>
<li><span style="color: #ff0000;">Dictionary</span>&lt;<span style="color: #0000ff;">string</span>, <span style="color: #0000ff;">object</span>&gt; collections;</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #008000;">// Get the stored DataServiceState object from the dictionary.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">var</span> state = <span style="color: #ff0000;">dictionary</span>[<span style="color: #a31515;">"DataServiceState"</span>] <span style="color: #0000ff;">as</span> <span style="color: #ff0000;">DataServiceState</span>;</li>
<li><span style="color: #0000ff;">if</span> (state != <span style="color: #0000ff;">null</span>)</li>
<li style="background: #f3f3f3;">{</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// Restore the context and binding collections.</span></li>
<li><span style="color: #ff0000;">NetflixCatalog</span> context</li>
<li style="background: #f3f3f3;">= state.<span style="color: #ff0000;">Restore</span>(<span style="color: #0000ff;">out</span> collections) <span style="color: #0000ff;">as</span> <span style="color: #ff0000;">NetflixCatalog</span>;</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// Get the binding collection of Title objects.</span></li>
<li><span style="color: #ff0000;">DataServiceCollection</span>&lt;Title&gt; titles</li>
<li style="background: #f3f3f3;">= collections[<span style="color: #a31515;">"Titles"</span>] <span style="color: #0000ff;">as</span> <span style="color: #ff0000;">DataServiceCollection</span>&lt;Title&gt;;</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// Initialize the application with stored data.</span></li>
<li><span style="color: #2b91af;">App</span>.<span style="color: #ff0000;">ViewModel</span>.LoadData(context, titles);</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #008000;">// Restore other view model data.</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">_currentPage</span> = (<span style="color: #0000ff;">int</span>)<span style="color: #ff0000;">dictionary</span>[<span style="color: #a31515;">"CurrentPage"</span>];</li>
<li><span style="color: #ff0000;">_totalCount</span> = (<span style="color: #0000ff;">int</span>)<span style="color: #ff0000;">dictionary</span>[<span style="color: #a31515;">"TotalCount"</span>];</li>
<li style="background: #f3f3f3;">}</li>
<li>}</li>
</ol></div>
</div>
</div>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:68851c4f-5e89-4a3d-937f-3c3e7be6317f" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">Visual Basic</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #008000;">' Restores the view model state from the supplied state dictionary.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Public</span> <span style="color: #0000ff;">Sub</span> RestoreState(dictionary <span style="color: #0000ff;">As</span> <span style="color: #2b91af;">IDictionary</span>(<span style="color: #0000ff;">Of</span> <span style="color: #0000ff;">String</span>, <span style="color: #0000ff;">Object</span>))</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">' Create a dictionary to hold any stored binding collections.</span></li>
<li><span style="color: #0000ff;">Dim</span> collections <span style="color: #0000ff;">As</span> <span style="color: #2b91af;">Dictionary</span>(<span style="color: #0000ff;">Of</span> <span style="color: #0000ff;">String</span>, <span style="color: #0000ff;">Object</span>)</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #008000;">' Get the stored DataServiceState object from the dictionary.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Dim</span> state = <span style="color: #0000ff;">TryCast</span>(dictionary(<span style="color: #a31515;">"DataServiceState"</span>), DataServiceState)</li>
<li><span style="color: #0000ff;">If</span> state <span style="color: #0000ff;">IsNot</span> <span style="color: #0000ff;">Nothing</span> <span style="color: #0000ff;">Then</span></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">' Restore the context and binding collections.</span></li>
<li><span style="color: #0000ff;">Dim</span> context <span style="color: #0000ff;">As</span> NetflixCatalog = <span style="color: #0000ff;">TryCast</span>(state.Restore(collections), NetflixCatalog)</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #008000;">' Get the binding collection of Title objects.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Dim</span> titles <span style="color: #0000ff;">As</span> DataServiceCollection(<span style="color: #0000ff;">Of</span> Title) = <span style="color: #0000ff;">TryCast</span>(collections(<span style="color: #a31515;">"Titles"</span>), DataServiceCollection(<span style="color: #0000ff;">Of</span> Title))</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">' Initialize the application with stored data.</span></li>
<li>App.ViewModel.LoadData(context, titles)</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #008000;">' Restore other view model data.</span></li>
<li style="background: #f3f3f3;">_currentPage = <span style="color: #0000ff;">CInt</span>(dictionary(<span style="color: #a31515;">"CurrentPage"</span>))</li>
<li>_totalCount = <span style="color: #0000ff;">CInt</span>(dictionary(<span style="color: #a31515;">"TotalCount"</span>))</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">If</span></li>
<li><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Sub</span></li>
</ol></div>
</div>
</div>
<p></p>
<h2></h2>
<h2><a name="AddServiceReference"></a>G&eacute;n&eacute;rer les classes de donn&eacute;es du client</h2>
<p>Vous pouvez utiliser l'outil DataSvcUtil.exe pour g&eacute;n&eacute;rer les classes de donn&eacute;es dans votre application qui repr&eacute;sente le mod&egrave;le de donn&eacute;es d'un service OData. Cet outil, qui est inclut avec les biblioth&egrave;ques OData sur CodePlex, se connecte au service de donn&eacute;es et g&eacute;n&egrave;re les classes de donn&eacute;es et le containeur de donn&eacute;es, qui h&eacute;rite de la classe DataServiceContext. La commande suivante g&eacute;n&egrave;re le mod&egrave;le de donn&eacute;es client bas&eacute; sur le service OData Netflix:</p>
<p><b>Command</b></p>
<h4><em>DataSvcUtil.exe /out:"Netflix.cs" /uri:"http://odata.netflix.com/v1/Catalog" /language:csharp /DataServiceCollection /version:2.0</em></h4>
<p>En utilisant le param&egrave;tre /DataServiceCollection dans la commande, les classes DataServiceCollection sont g&eacute;n&eacute;r&eacute;es pour chaque collection dans le mod&egrave;le.</p>
<p>L'outil DataSvcUtil.exe g&eacute;n&egrave;re le containeur de donn&eacute;es avec le m&ecirc;me nom que l'espace de nom du sch&eacute;ma. Pour simplifier les r&eacute;f&eacute;rences, l'espace de nom des classes de donn&eacute;es g&eacute;n&eacute;r&eacute;es ont &eacute;t&eacute; modifi&eacute;es manuellement.</p>
<p></p>
<h2></h2>
<h2>Voir aussi</h2>
<ul>
<li><a href="http://go.microsoft.com/fwlink/?LinkID=182204">Open Data Protocol Web site</a>.</li>
<li><a href="http://go.microsoft.com/fwlink/?LinkId=212402">Netflix public catalog as OData feeds</a>.</li>
<li><a href="http://go.microsoft.com/fwlink/?LinkId=212404">Implementing the Model-View-ViewModel Pattern in a Windows Phone Application</a>.</li>
<li><a href="http://go.microsoft.com/fwlink/?LinkId=212449">How to: Consume an OData Service for Windows Phone</a>.</li>
</ul>
<hr />
<p><a href="#sommaire">Cliquez ici pour revenir au sommaire de la liste d&rsquo;articles</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Developpement Windows Phone - partie 20</title>
      <link>https://docs.microsoft.com/archive/blogs/lgmorand/developpement-windows-phone-partie-20</link>
      <pubDate>Tue, 06 Sep 2011 13:20:00 GMT</pubDate>
      <dc:creator><![CDATA[Louis-Guillaume Morand]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/lgmorand/2011/09/06/developpement-windows-phone-partie-20/</guid>
      <description><![CDATA[Data Binding
Cet article fait partie d&rsquo;une s&eacute;rie d&rsquo;articles sur le...]]></description>
      <content:encoded><![CDATA[<h1>Data Binding</h1>
<p>Cet article fait partie d&rsquo;une s&eacute;rie d&rsquo;articles sur le d&eacute;veloppement Windows Phone. Il s&rsquo;agit d&rsquo;une traduction des articles se trouvant <a href="http://create.msdn.com/en-us/education/quickstarts" target="_blank">sur la MSDN</a>.</p>
<h2><a name="sommaire"></a>Sommaire</h2>
<p><strong>Bien d&eacute;buter et fondamentaux</strong></p>
<ul>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-1.aspx" target="_blank">Bien d&eacute;marrer (Hello World)</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-2.aspx" target="_blank">Cr&eacute;er une interface utilisateur pour Windows Phone en XAML</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-3.aspx" target="_blank">Utiliser des contr&ocirc;les</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-4.aspx" target="_blank">Types de contr&ocirc;les</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-5.aspx" target="_blank">Contr&ocirc;les Panorama et Pivot</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-6.aspx" target="_blank">Travailler avec du texte sur le Windows Phone</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-7.aspx" target="_blank">Mise en page sur l&rsquo;&eacute;cran</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-8.aspx" target="_blank">Orientations de l&rsquo;&eacute;cran</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-9.aspx" target="_blank">Saisie tactile</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-10.aspx" target="_blank">Navigation</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-11.aspx" target="_blank">Ex&eacute;cuter votre application en arri&egrave;re-plan (tombstoning)</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-12.aspx" target="_blank">Notifications Push pour le d&eacute;veloppement Windows Phone</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-13.aspx" target="_blank">Publier votre application sur le Marketplace</a></li>
</ul>
<p><strong>Visuels et m&eacute;dia</strong></p>
<ul>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-14.aspx" target="_blank">Images</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-15.aspx" target="_blank">Animations</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-16.aspx" target="_blank">Vid&eacute;o et Audio</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-17.aspx" target="_blank">Graphiques</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-18.aspx" target="_blank">Pinceaux</a></li>
</ul>
<p><strong>Travailler avec les donn&eacute;es</strong></p>
<ul>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-19.aspx" target="_blank">Obtenir des donn&eacute;es dans vos applications Windows Phone</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-20.aspx" target="_blank">Data binding</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-21.aspx" target="_blank">Isolated storage</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-22.aspx" target="_blank">Acc&eacute;der &agrave; un service Web REST</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-23.aspx" target="_blank">Consommer des donn&eacute;es Windows Azure</a></li>
</ul>
<p><strong>Sondes et autres fonctionnalit&eacute;s sp&eacute;cifiques au t&eacute;l&eacute;phone</strong></p>
<ul>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-24.aspx" target="_blank">Lanceurs et choosers</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-25.aspx" target="_blank">D&eacute;tecter des mouvements (acc&eacute;l&eacute;rom&egrave;tres)</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-26.aspx" target="_blank">D&eacute;velopper avec le GPS Windows Phone (Services de localisation)</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-27.aspx" target="_blank">D&eacute;velopper avec l&rsquo;appareil photo du Windows Phone</a></li>
</ul>
<hr />
<h1>Data Binding</h1>
<p>La plupart des applications Windows Phone affichent des donn&eacute;es dans les contr&ocirc;les. Dans de nombreux cas, les donn&eacute;es sont des objets business tels que des actions en bourse, des titres de news ou des images. En plus, vous voulez souvent autoriser l'utilisateur &agrave; s&eacute;lectionner un &eacute;l&eacute;ment depuis une liste puis afficher les d&eacute;tails relatifs &agrave; cet &eacute;l&eacute;ment dans un autre contr&ocirc;le comme par exemple une zone de texte.</p>
<p>Ce tutoriel montre comment lier un contr&ocirc;le &agrave; un simple &eacute;l&eacute;ment et comment lier un contr&ocirc;le de liste &agrave; une collection d'&eacute;l&eacute;ments, De plus, vous verrez au sein de cet article comment personnaliser l'affichage des &eacute;l&eacute;ments, comment impl&eacute;menter une vue d&eacute;taill&eacute;e bas&eacute;e sur une s&eacute;lection et comment convertir les donn&eacute;es avant de les afficher.</p>
<p>Ce tutoriel contient les sections suivantes:</p>
<ul>
<li><a href="#BindingSingleItem">Lier un contr&ocirc;le &agrave; un &eacute;l&eacute;ment unique</a></li>
<li><a href="#BindingToCollection">Lier un contr&ocirc;le &agrave; une collection d'objets</a></li>
<li><a href="#DisplayingItemsWithDataTemplate">Afficher les &eacute;l&eacute;ments dans un contr&ocirc;le en utilisant un data template</a></li>
<li><a href="#AddingDetailsView">Ajouter une vue d&eacute;tails</a></li>
<li><a href="#ConvertingData">Convertir des donn&eacute;es pour les afficher dans des contr&ocirc;les</a></li>
</ul>
<p></p>
<h2></h2>
<h2><a name="BindingSingleItem"></a>Lier un contr&ocirc;le &agrave; un &eacute;l&eacute;ment unique</h2>
<p>Une liaison de donn&eacute;es (data binding) consiste en une source et une cible. La cible du binding est g&eacute;n&eacute;ralement une propri&eacute;t&eacute; d'un contr&ocirc;le et doit &ecirc;tre une <a href="http://go.microsoft.com/fwlink/?LinkId=130073">DependencyProperty</a>.</p>
<p>L'exemple suivant montre un contr&ocirc;le li&eacute; &agrave; un &eacute;l&eacute;ment unique. La cible est la propri&eacute;t&eacute; <b>Text</b> d'un contr&ocirc;le Textbox. La source est une simple classe Recording.</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:46368d3a-3f54-4318-a6ec-6f278fe8d515" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">XAML</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">Grid</span><span style="color: #ff0000;"> x</span><span style="color: #0000ff;">:</span><span style="color: #ff0000;">Name</span><span style="color: #0000ff;">="ContentPanel"</span><span style="color: #ff0000;"> Grid.Row</span><span style="color: #0000ff;">="1"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="12,0,12,0"&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">TextBox</span><span style="color: #ff0000;"> VerticalAlignment</span><span style="color: #0000ff;">="Top"</span><span style="color: #ff0000;"> IsReadOnly</span><span style="color: #0000ff;">="True"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="5"</span></li>
<li><span style="color: #ff0000;">TextWrapping</span><span style="color: #0000ff;">="Wrap"</span><span style="color: #ff0000;"> Height</span><span style="color: #0000ff;">="120"</span><span style="color: #ff0000;"> Width</span><span style="color: #0000ff;">="400"</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="{</span><span style="color: #a31515;">Binding}</span><span style="color: #0000ff;">"</span><span style="color: #ff0000;"> x</span><span style="color: #0000ff;">:</span><span style="color: #ff0000;">Name</span><span style="color: #0000ff;">="textBox1" /&gt;</span></li>
<li><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">Grid</span><span style="color: #0000ff;">&gt;</span></li>
</ol></div>
</div>
</div>
<p></p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:829009e3-314c-4898-b6f5-a19f301b7f2d" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">C#</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #008000;">// Constructor</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">public</span> MainPage()</li>
<li>{</li>
<li style="background: #f3f3f3;">InitializeComponent();</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// Set the data context to a new Recording.</span></li>
<li><span style="color: #ff0000;">textBox1</span>.DataContext = <span style="color: #0000ff;">new</span> <span style="color: #ff0000;">Recording</span>(<span style="color: #a31515;">"Chris Sells"</span>, <span style="color: #a31515;">"Chris Sells Live"</span>,</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">new</span> <span style="color: #ff0000;">DateTime</span>(2008, 2, 5));</li>
<li></li>
<li style="background: #f3f3f3;">}</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// A simple business object</span></li>
<li><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> <span style="color: #ff0000;">Recording</span></li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #0000ff;">public</span> <span style="color: #ff0000;">Recording</span>() { }</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #0000ff;">public</span> <span style="color: #ff0000;">Recording</span>(<span style="color: #0000ff;">string</span> <span style="color: #ff0000;">artistName</span>, <span style="color: #0000ff;">string</span> cdName, DateTime <span style="color: #ff0000;">release</span>)</li>
<li style="background: #f3f3f3;">{</li>
<li>Artist = <span style="color: #ff0000;">artistName</span>;</li>
<li style="background: #f3f3f3;">Name = cdName;</li>
<li><span style="color: #ff0000;">ReleaseDate</span> = <span style="color: #ff0000;">release</span>;</li>
<li style="background: #f3f3f3;">}</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">string</span> Artist { <span style="color: #ff0000;">get</span>; <span style="color: #ff0000;">set</span>; }</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">string</span> Name { <span style="color: #ff0000;">get</span>; <span style="color: #ff0000;">set</span>; }</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">public</span> DateTime <span style="color: #ff0000;">ReleaseDate</span> { <span style="color: #ff0000;">get</span>; <span style="color: #ff0000;">set</span>; }</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// Override the ToString method.</span></li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">string</span> ToString()</li>
<li>{</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">return</span> Name + <span style="color: #a31515;">" by "</span> + Artist + <span style="color: #a31515;">", Released: "</span> + <span style="color: #ff0000;">ReleaseDate</span>.ToShortDateString();</li>
<li>}</li>
<li style="background: #f3f3f3;">}</li>
</ol></div>
</div>
</div>
<p></p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:8b316824-b063-4549-a11e-51f3b2e16120" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">Visual Basic</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #008000;">' Constructor</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Public</span> <span style="color: #0000ff;">Sub</span> <span style="color: #0000ff;">New</span>()</li>
<li>InitializeComponent()</li>
<li style="background: #f3f3f3;"><span style="color: #008000;">' Set the data context to a new recording.</span></li>
<li>textBox1.DataContext = <span style="color: #0000ff;">New</span> <span style="color: #2b91af;">Recording</span>(<span style="color: #a31515;">"Chris Sells"</span>, <span style="color: #a31515;">"Chris Sells Live"</span>, _</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">New</span> <span style="color: #2b91af;">DateTime</span>(2008, 2, 5))</li>
<li><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Sub</span></li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #0000ff;">Public</span> <span style="color: #0000ff;">Class</span> <span style="color: #2b91af;">Recording</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Public</span> <span style="color: #0000ff;">Sub</span> <span style="color: #0000ff;">New</span>()</li>
<li><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Sub</span></li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #0000ff;">Public</span> <span style="color: #0000ff;">Sub</span> <span style="color: #0000ff;">New</span>(<span style="color: #0000ff;">ByVal</span> artistName <span style="color: #0000ff;">As</span> <span style="color: #0000ff;">String</span>, <span style="color: #0000ff;">ByVal</span> cdName <span style="color: #0000ff;">As</span> <span style="color: #0000ff;">String</span>, _</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">ByVal</span> release <span style="color: #0000ff;">As</span> <span style="color: #2b91af;">DateTime</span>)</li>
<li>Artist = artistName</li>
<li style="background: #f3f3f3;">Name = cdName</li>
<li>ReleaseDate = release</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Sub</span></li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Public</span> <span style="color: #0000ff;">Property</span> Artist <span style="color: #0000ff;">As</span> <span style="color: #0000ff;">String</span></li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Public</span> <span style="color: #0000ff;">Property</span> Name <span style="color: #0000ff;">As</span> <span style="color: #0000ff;">String</span></li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Public</span> <span style="color: #0000ff;">Property</span> ReleaseDate <span style="color: #0000ff;">As</span> <span style="color: #2b91af;">DateTime</span></li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">' Override ToString.</span></li>
<li><span style="color: #0000ff;">Public</span> <span style="color: #0000ff;">Overloads</span> <span style="color: #0000ff;">Overrides</span> <span style="color: #0000ff;">Function</span> ToString() <span style="color: #0000ff;">As</span> <span style="color: #0000ff;">String</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Return</span> Name + <span style="color: #a31515;">" by "</span> + Artist + <span style="color: #a31515;">", Released: "</span> + releaseDate.ToShortDateString()</li>
<li><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Function</span></li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Class</span></li>
</ol></div>
</div>
</div>
<p>Voici le r&eacute;sultat:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/5482.image_thumb1_3968723C.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/5482.image_5F00_thumb1_5F00_3968723C.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image_thumb1" alt="image_thumb1" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/5315.image_thumb1_thumb_173066B6.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/5315.image_5F00_thumb1_5F00_thumb_5F00_173066B6.png" border="0" height="372" width="202" /></a></p>
<p>Pour afficher un enregistrement musical dans une zone de texte, la propri&eacute;t&eacute; <b>Text</b> du contr&ocirc;le est d&eacute;finie sur un <a href="http://go.microsoft.com/fwlink/?LinkId=130074">Binding</a> en utilisant une extension de balisage (<i>markup extension</i>). Dans cet exemple, le mode de binding par d&eacute;faut est <a href="http://go.microsoft.com/fwlink/?LinkId=130075">BindingMode.OneWay</a>, ce qui signifie que les donn&eacute;es sont r&eacute;cup&eacute;r&eacute;es de la source, mais les changements ne sont pas propag&eacute;s vers la source. Pour plus d'informations sur les <i>markup extensions</i> et leur syntaxe, lisez l'article MSDN <a href="http://go.microsoft.com/fwlink/?LinkId=111919">Binding Markup Extension</a>.</p>
<p>La classe Recording poss&egrave;de trois propri&eacute;t&eacute;s publiques et une surcharge de la m&eacute;thode <b>ToString().</b> Les propri&eacute;t&eacute;s sont Artist, Name, et ReleaseDate. La m&eacute;thode <b>ToString</b> est importante car si aucun formatage n'est sp&eacute;cifi&eacute;, la m&eacute;thode <b>ToString</b> est appel&eacute;e sur un objet li&eacute; pour des raisons d'affichage. La propri&eacute;t&eacute; <a href="http://go.microsoft.com/fwlink/?LinkId=130076">Binding.Source</a> n'est pas d&eacute;finie directement, au contraire, la propri&eacute;t&eacute; <a href="http://go.microsoft.com/fwlink/?LinkId=130078">FrameworkElement.DataContext</a> de la <b>TextBox</b> est param&eacute;tr&eacute;e sur un nouvel objet Recording.</p>
<p></p>
<h2></h2>
<h2><a name="BindingToCollection"></a>Lier un contr&ocirc;le &agrave; une collection d'objets</h2>
<p>L'exemple suivant d&eacute;montre la syntaxe que vous utilisez pour lier des donn&eacute;es &agrave; un contr&ocirc;le mais n'est pas tr&egrave;s r&eacute;aliste. Un sc&eacute;nario plus commun est de lier une collection d'objets m&eacute;tier. La classe g&eacute;n&eacute;rique <a href="http://go.microsoft.com/fwlink/?LinkId=130079">ObservableCollection</a> est un bon choix pour le data binding car elle impl&eacute;mente les interfaces <a href="http://go.microsoft.com/fwlink/?LinkId=130080">INotifyPropertyChanged</a> et <a href="http://go.microsoft.com/fwlink/?LinkId=130081">INotifyCollectionChanged</a>. Ces interfaces fournissent les notifications de changement aux contr&ocirc;les li&eacute;s lorsque qu'un &eacute;l&eacute;ment de la liste ou une propri&eacute;t&eacute; de la liste elle-m&ecirc;me change. Si vous voulez que vos contr&ocirc;les li&eacute;s se mettent &agrave; jour lorsque les propri&eacute;t&eacute;s des objets de la collection changent, alors ces objets doivent &eacute;galement impl&eacute;menter <b>INotifyPropertyChanged</b>.</p>
<p>L'exemple suivant lie une collection d&rsquo;enregistrements musicaux &agrave; une <b>ComboBox</b>. Cliquez sur la fl&egrave;che de la combobox pour voir la liste des &eacute;l&eacute;ments li&eacute;s.</p>
<p><object data="data:application/x-silverlight-2," type="application/x-silverlight-2" autoupdate="true" height="550" width="400"><param name="source" value="http://create.msdn.com/assets/cms/docs/QuickstartsXAP/Binding_qs_2.xap" /><param name="minRuntimeVersion" value="3.0.40624.0" /><param name="background" value="White" /><param name="autoUpgrade" value="true" /><a href="http://go.microsoft.com/fwlink/?LinkID=149156&amp;v=3.0.40624.0" style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style: none;" /> </a> </object></p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:2d66858f-14de-432f-a0e7-e59f1e5b5cc0" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">XAML</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">Grid</span><span style="color: #ff0000;"> x</span><span style="color: #0000ff;">:</span><span style="color: #ff0000;">Name</span><span style="color: #0000ff;">="ContentPanel"</span><span style="color: #ff0000;"> Grid.Row</span><span style="color: #0000ff;">="1"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="12,0,12,0"&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">ComboBox</span><span style="color: #ff0000;"> x</span><span style="color: #0000ff;">:</span><span style="color: #ff0000;">Name</span><span style="color: #0000ff;">="ComboBox1"</span><span style="color: #ff0000;"> ItemsSource</span><span style="color: #0000ff;">="{</span><span style="color: #a31515;">Binding}</span><span style="color: #0000ff;">"</span></li>
<li><span style="color: #ff0000;">Foreground</span><span style="color: #0000ff;">="Black"</span><span style="color: #ff0000;"> FontSize</span><span style="color: #0000ff;">="18"</span><span style="color: #ff0000;"> Height</span><span style="color: #0000ff;">="50"</span><span style="color: #ff0000;"> Width</span><span style="color: #0000ff;">="400"/&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">Grid</span><span style="color: #0000ff;">&gt;</span></li>
</ol></div>
</div>
</div>
<p></p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:c0541603-945b-483a-9109-cbfc0c414dfc" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">C#</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">public</span> <span style="color: #ff0000;">ObservableCollection</span>&lt;<span style="color: #ff0000;">Recording</span>&gt; MyMusic = <span style="color: #0000ff;">new</span> <span style="color: #ff0000;">ObservableCollection</span>&lt;<span style="color: #ff0000;">Recording</span>&gt;();</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">public</span> <span style="color: #ff0000;">Page</span>()</li>
<li>{</li>
<li style="background: #f3f3f3;">InitializeComponent();</li>
<li><span style="color: #008000;">// Add items to the collection.</span></li>
<li style="background: #f3f3f3;">MyMusic.<span style="color: #ff0000;">Add</span>(<span style="color: #0000ff;">new</span> <span style="color: #ff0000;">Recording</span>(<span style="color: #a31515;">"Chris Sells"</span>, <span style="color: #a31515;">"Chris Sells Live"</span>,</li>
<li><span style="color: #0000ff;">new</span> <span style="color: #ff0000;">DateTime</span>(2008, 2, 5)));</li>
<li style="background: #f3f3f3;">MyMusic.<span style="color: #ff0000;">Add</span>(<span style="color: #0000ff;">new</span> <span style="color: #ff0000;">Recording</span>(<span style="color: #a31515;">"Luka Abrus"</span>,</li>
<li><span style="color: #a31515;">"The Road to Redmond"</span>, <span style="color: #0000ff;">new</span> <span style="color: #ff0000;">DateTime</span>(2007, 4, 3)));</li>
<li style="background: #f3f3f3;">MyMusic.<span style="color: #ff0000;">Add</span>(<span style="color: #0000ff;">new</span> <span style="color: #ff0000;">Recording</span>(<span style="color: #a31515;">"Jim Hance"</span>,</li>
<li><span style="color: #a31515;">"The Best of Jim Hance"</span>, <span style="color: #0000ff;">new</span> <span style="color: #ff0000;">DateTime</span>(2007, 2, 6)));</li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// Set the data context for the combo box.</span></li>
<li><span style="color: #ff0000;">ComboBox1</span>.DataContext = MyMusic;</li>
<li style="background: #f3f3f3;">}</li>
</ol></div>
</div>
</div>
<p></p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e0e415bb-ab57-4d4d-9d90-23e2ee1de088" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">Visual Basic</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">Public</span> MyMusic <span style="color: #0000ff;">As</span> <span style="color: #0000ff;">New</span> ObservableCollection(<span style="color: #0000ff;">Of</span> Recording)()</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Public</span> <span style="color: #0000ff;">Sub</span> <span style="color: #0000ff;">New</span>()</li>
<li>InitializeComponent()</li>
<li style="background: #f3f3f3;"><span style="color: #008000;">' Add items to the collection.</span></li>
<li>MyMusic.Add(<span style="color: #0000ff;">New</span> Recording(<span style="color: #a31515;">"Chris Sells"</span>, <span style="color: #a31515;">"Chris Sells Live"</span>, _</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">New</span> <span style="color: #2b91af;">DateTime</span>(2008, 2, 5)))</li>
<li>MyMusic.Add(<span style="color: #0000ff;">New</span> Recording(<span style="color: #a31515;">"Luka Abrus"</span>, <span style="color: #a31515;">"The Road to Redmond"</span>, _</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">New</span> <span style="color: #2b91af;">DateTime</span>(2007, 4, 3)))</li>
<li>MyMusic.Add(<span style="color: #0000ff;">New</span> Recording(<span style="color: #a31515;">"Jim Hance"</span>, <span style="color: #a31515;">"The Best of Jim Hance"</span>, _</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">New</span> <span style="color: #2b91af;">DateTime</span>(2007, 2, 6)))</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">' Set the data context for the combo box.</span></li>
<li>ComboBox1.DataContext = MyMusic</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Sub</span></li>
</ol></div>
</div>
</div>
<p>Pour afficher les enregistrements musicaux dans la <b>ComboBox</b>, la propri&eacute;t&eacute; <a href="http://go.microsoft.com/fwlink/?LinkId=130086">ItemsControl.ItemsSource</a> est d&eacute;finie sur un <a href="http://go.microsoft.com/fwlink/?LinkId=130074">Binding</a>, et la propri&eacute;t&eacute; <a href="http://go.microsoft.com/fwlink/?LinkId=130078">FrameworkElement.DataContext</a> du contr&ocirc;le <b>ComboBox</b> est d&eacute;finie sur une collection d'objets Recording. Un <b>ComboBoxItem</b> est cr&eacute;&eacute; pour chaque &eacute;l&eacute;ment de la collection. La m&eacute;thode <b>ToString</b> est automatiquement appel&eacute;e sur chaque objet Recording &agrave; afficher dans l'item de la combobox.</p>
<p></p>
<h2></h2>
<h2><a name="DisplayingItemsWithDataTemplate"></a>Afficher les &eacute;l&eacute;ments dans un contr&ocirc;le en utilisant un data template</h2>
<p>Vous pouvez afficher les &eacute;l&eacute;ments dans une liste en utilisant la m&eacute;thode ToString() de chaque &eacute;l&eacute;ment. N&eacute;anmoins, le sc&eacute;nario le plus courant est de fournir un affichage personnalis&eacute; gr&acirc;ce &agrave; l'utilisation d'un <a href="http://go.microsoft.com/fwlink/?LinkId=130082">DataTemplate</a>. Un <b>DataTemplate</b> vous permet de personnaliser la fa&ccedil;on dont les &eacute;l&eacute;ments sont affich&eacute;s dans le contr&ocirc;le. Typiquement, vous d&eacute;finissez le data template en utilisant la propri&eacute;t&eacute; <a href="http://go.microsoft.com/fwlink/?LinkId=130083">ContentControl.ContentTemplate</a> d'un contr&ocirc;le de contenu ou la propri&eacute;t&eacute; <a href="http://go.microsoft.com/fwlink/?LinkId=130084">ItemsControl.ItemTemplate</a> d'un contr&ocirc;le &agrave; &eacute;l&eacute;ments.</p>
<p>L'exemple suivant montre la m&ecirc;me liste d&rsquo;enregistrements li&eacute;s &agrave; une combobox en utilisant un data template. Une combobox est un <a href="http://go.microsoft.com/fwlink/?LinkId=130085">ItemsControl</a>, ce qui signifie que vous &eacute;tablissez un data template pour chaque &eacute;l&eacute;ment en d&eacute;finissant sa propri&eacute;t&eacute; <b>ItemTemplate</b> sur un data template. Pour essayer cet exemple, cliquez sur la fl&egrave;che du bas pour voir la liste des enregistrements. Notez comment l'enregistrement apparait diff&eacute;remment de l'exemple suivant. L'artiste et le nom du CD sont affich&eacute;s dans un format personnalis&eacute;.</p>
<p><object data="data:application/x-silverlight-2," type="application/x-silverlight-2" autoupdate="true" height="550" width="400"><param name="source" value="http://create.msdn.com/assets/cms/docs/QuickstartsXAP/Binding_qs_3.xap" /><param name="minRuntimeVersion" value="3.0.40624.0" /><param name="background" value="White" /><param name="autoUpgrade" value="true" /><a href="http://go.microsoft.com/fwlink/?LinkID=149156&amp;v=3.0.40624.0" style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style: none;" /> </a> </object></p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:4a336d65-f05a-479d-ac22-ad27c35956db" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">XAML</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">ComboBox</span><span style="color: #ff0000;"> x</span><span style="color: #0000ff;">:</span><span style="color: #ff0000;">Name</span><span style="color: #0000ff;">="ComboWithTemplate"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="5"</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="450"</span><span style="color: #ff0000;"> Height</span><span style="color: #0000ff;">="50"</span><span style="color: #ff0000;"> HorizontalAlignment</span><span style="color: #0000ff;">="Left"</span></li>
<li><span style="color: #ff0000;">ItemsSource</span><span style="color: #0000ff;">="{</span><span style="color: #a31515;">Binding}</span><span style="color: #0000ff;">"</span><span style="color: #ff0000;"> Foreground</span><span style="color: #0000ff;">="Black"</span><span style="color: #ff0000;"> FontSize</span><span style="color: #0000ff;">="18" &gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">ComboBox.ItemTemplate</span><span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">DataTemplate</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">StackPanel</span><span style="color: #ff0000;"> Orientation</span><span style="color: #0000ff;">="Horizontal"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="2"&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">TextBlock</span><span style="color: #ff0000;"> Text</span><span style="color: #0000ff;">="Artist:"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="2" /&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">TextBlock</span><span style="color: #ff0000;"> Text</span><span style="color: #0000ff;">="{</span><span style="color: #a31515;">Binding</span><span style="color: #ff0000;"> Artist}</span><span style="color: #0000ff;">"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="2" /&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">TextBlock</span><span style="color: #ff0000;"> Text</span><span style="color: #0000ff;">="CD:"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="10,2,0,2" /&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">TextBlock</span><span style="color: #ff0000;"> Text</span><span style="color: #0000ff;">="{</span><span style="color: #a31515;">Binding</span><span style="color: #ff0000;"> Name}</span><span style="color: #0000ff;">"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="2" /&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">StackPanel</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">DataTemplate</span><span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">ComboBox.ItemTemplate</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">ComboBox</span><span style="color: #0000ff;">&gt;</span></li>
</ol></div>
</div>
</div>
<p>Dans le XAML, vous pouvez voir la d&eacute;finition du data template. Le data template contient un <b>StackPanel</b> avec quatre contr&ocirc;les <b>TextBlock</b>. Le StackPanel a une orientation horizontale pour que les quatre blocs de texte apparaissent c&ocirc;te &agrave; c&ocirc;te. Deux des contr&ocirc;les <b>TextBlock</b> sont li&eacute;s aux propri&eacute;t&eacute;s Artist et Name de l'objet Recording. Les deux autres contr&ocirc;les <b>TextBlock</b> affichent du texte statique. Pour chaque &eacute;l&eacute;ment li&eacute;, le binding fournit le chemin vers la propri&eacute;t&eacute; sur l'objet Recording. Comme dans l'exemple pr&eacute;c&eacute;dent, ce binding se base sur le fait que le data context soit li&eacute; &agrave; la liste des objets Recordings.</p>
<p>Ce XAML utilise la syntaxe par propri&eacute;t&eacute; d'&eacute;l&eacute;ment. Pour plus d'informations sur cette syntaxe, lisez le tutoriel <a href="http://create.msdn.com/en-US/education/quickstarts/xaml.aspx">XAML QuickStart</a>.</p>
<p></p>
<h2></h2>
<h2><a name="AddingDetailsView"></a>Ajouter une vue d&eacute;tails</h2>
<p>Pour afficher les d&eacute;tails d'un &eacute;l&eacute;ment lorsqu'il est s&eacute;lectionn&eacute; dans une collection, vous devez cr&eacute;er une UI appropri&eacute;e et lier l'UI aux donn&eacute;es que vous voulez afficher. De plus, vous devez utiliser une <a href="http://msdn.microsoft.com/library/system.windows.data.collectionviewsource%28VS.95%29.aspx">CollectionViewSource</a> en tant que contexte de donn&eacute;es pour permettre &agrave; la vue d&eacute;tails de lier l'&eacute;l&eacute;ment courant.</p>
<p>L'exemple suivant montre la m&ecirc;me liste d'enregistrements mais cette fois la liste est la source de donn&eacute;es d'une instance de <a href="http://msdn.microsoft.com/library/system.windows.data.collectionviewsource%28VS.95%29.aspx">CollectionViewSource</a>. Le contexte de donn&eacute;es de l'&eacute;l&eacute;ment racine du layout est d&eacute;fini sur la CollectionViewSource et la combobox ainsi que la vue d&eacute;tails h&eacute;ritent du contexte de donn&eacute;es de l'&eacute;l&eacute;ment racine. Cela permet &agrave; la combobox d'afficher la liste d'&eacute;l&eacute;ments pendant que la vue d&eacute;tails affiche les informations de l'&eacute;l&eacute;ment courant.</p>
<p><object data="data:application/x-silverlight-2," type="application/x-silverlight-2" autoupdate="true" height="550" width="400"><param name="source" value="http://create.msdn.com/assets/cms/docs/QuickstartsXAP/Binding_qs_4.xap" /><param name="minRuntimeVersion" value="3.0.40624.0" /><param name="background" value="White" /><param name="autoUpgrade" value="true" /><a href="http://go.microsoft.com/fwlink/?LinkID=149156&amp;v=3.0.40624.0" style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style: none;" /> </a> </object></p>
<p></p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e70f2929-b81f-491f-a382-17248e113856" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">XAML</div>
<div style="background: #ddd; max-height: 500px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #008000;">&lt;!--The UI for the details view--&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">StackPanel</span><span style="color: #ff0000;"> x</span><span style="color: #0000ff;">:</span><span style="color: #ff0000;">Name</span><span style="color: #0000ff;">="RecordingDetails"&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">TextBlock</span><span style="color: #ff0000;"> FontWeight</span><span style="color: #0000ff;">="Bold"</span><span style="color: #ff0000;"> Text</span><span style="color: #0000ff;">="{</span><span style="color: #a31515;">Binding</span><span style="color: #ff0000;"> Artist}</span><span style="color: #0000ff;">"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="5,0,0,0"/&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">TextBlock</span><span style="color: #ff0000;"> FontStyle</span><span style="color: #0000ff;">="Italic"</span><span style="color: #ff0000;"> Text</span><span style="color: #0000ff;">="{</span><span style="color: #a31515;">Binding</span><span style="color: #ff0000;"> Name}</span><span style="color: #0000ff;">"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="5,0,0,0"/&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">TextBlock</span><span style="color: #ff0000;"> Text</span><span style="color: #0000ff;">="{</span><span style="color: #a31515;">Binding</span><span style="color: #ff0000;"> ReleaseDate}</span><span style="color: #0000ff;">"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="5,0,0,0" /&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">StackPanel</span><span style="color: #0000ff;">&gt;</span></li>
</ol></div>
</div>
</div>
<p></p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1456b072-2693-4899-b1e0-ad63fa1db537" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">C#</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #008000;">//ComboWithTemplate.DataContext = MyMusic;</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">LayoutRoot</span>.DataContext = <span style="color: #0000ff;">new</span> <span style="color: #ff0000;">CollectionViewSource</span> { <span style="color: #ff0000;">Source</span> = <span style="color: #ff0000;">MyMusic</span> };</li>
</ol></div>
</div>
</div>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:34a24192-b2cc-4d02-a737-9ad3fe5ce214" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">Visual Basic</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #008000;">'ComboWithTemplate.DataContext = MyMusic</span></li>
<li style="background: #f3f3f3;">LayoutRoot.DataContext = <span style="color: #0000ff;">New</span> CollectionViewSource <span style="color: #0000ff;">With</span> {.Source = MyMusic}</li>
</ol></div>
</div>
</div>
<p>Dans cet exemple, un <b>StackPanel</b> est ajout&eacute; au user control qui contient la combobox existante. Un <b>Rectangle</b> sert de ligne de division sous la <b>ComboBox</b>. A c&ocirc;t&eacute; se trouve un StackPanel qui contient quatre blocs pour afficher les d&eacute;tails de l'enregistrement. La propri&eacute;t&eacute; <b>TextBlock.Text</b> de chaque bloc de texte est li&eacute;e &agrave; une propri&eacute;t&eacute; de l'objet Recording.</p>
<p></p>
<h2></h2>
<h2><a name="ConvertingData"></a>Convertir des donn&eacute;es pour les afficher dans des contr&ocirc;les</h2>
<p>Si vous voulez formater et afficher un type non-string dans un contr&ocirc;le, tel qu'un textbox, vous pouvez utiliser un convertisseur. Par exemple, vous pourriez afficher un label et une date format&eacute;e plut&ocirc;t que la date. (Note : vous pouvez utiliser la propri&eacute;t&eacute; <a href="http://msdn.microsoft.com/library/system.windows.data.bindingbase.stringformat%28VS.95%29.aspx">BindingBase.StringFormat</a> si vous souhaitez uniquement modifier le format de la date.)</p>
<p>L'exemple suivant montre l'impl&eacute;mentation d'un convertisseur pour la date de sortie dans la liste des enregistrements. Pour essayer cet exemple, cliquez sur la fl&egrave;che du combobox et s&eacute;lectionnez un &eacute;l&eacute;ment diff&eacute;rent. Notez que l'affichage de la date dans la liste d&eacute;roulante et dans la vue d&eacute;taill&eacute;e est affich&eacute; dans un format personnalis&eacute;.</p>
<p><span id="preserve235132462d8e462ea1012693d968eb74" class="wlWriterPreserve"><object data="data:application/x-oleobject;base64,QfXq3+HzJEysrJnDBxUISgAJAABXKQAA2DgAAAwAAABXAGgAaQB0AGUAAAAAAAAAAAAAAAAAAACOAAAAaAB0AHQAcAA6AC8ALwBjAHIAZQBhAHQAZQAuAG0AcwBkAG4ALgBjAG8AbQAvAGEAcwBzAGUAdABzAC8AYwBtAHMALwBkAG8AYwBzAC8AUQB1AGkAYwBrAHMAdABhAHIAdABzAFgAQQBQAC8AQgBpAG4AZABpAG4AZwBfAHEAcwBfADQALgB4AGEAcAAAADwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAQAAAAAAAAAAAAAAAAAAABgAAAAzAC4AMAAuADQAMAA2ADIANAAuADAAAAAKAAAAdAByAHUAZQAAAAAAAAAAAAAAAAAAAA==" type="application/x-silverlight-2" autoupdate="true" height="550" width="400"> <a href="http://go.microsoft.com/fwlink/?LinkID=149156&amp;v=3.0.40624.0" style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=161376" wlcopysrcurl="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft 
Silverlight" style="border-style: none;" /> </a> </object></span></p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:a9d9d622-6c11-4de6-b14b-7fc817c6e757" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">XAML</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">phone</span><span style="color: #0000ff;">:</span><span style="color: #a31515;">PhoneApplicationPage</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">x</span><span style="color: #0000ff;">:</span><span style="color: #ff0000;">Class</span><span style="color: #0000ff;">="MyExample.MainPage"</span></li>
<li><span style="color: #ff0000;">xmlns</span><span style="color: #0000ff;">="http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">xmlns</span><span style="color: #0000ff;">:</span><span style="color: #ff0000;">x</span><span style="color: #0000ff;">="http://schemas.microsoft.com/winfx/2006/xaml"</span></li>
<li><span style="color: #ff0000;">xmlns</span><span style="color: #0000ff;">:</span><span style="color: #ff0000;">local</span><span style="color: #0000ff;">="clr-namespace:</span><span style="color: #ff0000;">MyExample</span><span style="color: #0000ff;">"</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">...</span></li>
<li><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">phone</span><span style="color: #0000ff;">:</span><span style="color: #a31515;">PhoneApplicationPage.Resources</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">local</span><span style="color: #0000ff;">:</span><span style="color: #ff0000;">StringFormatter x</span><span style="color: #0000ff;">:</span><span style="color: #ff0000;">Key</span><span style="color: #0000ff;">="StringConverter"/&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">phone</span><span style="color: #0000ff;">:</span><span style="color: #a31515;">PhoneApplicationPage.Resources</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;">...</span></li>
<li><span style="color: #a31515;"></span><span style="color: #008000;">&lt;!--ContentPanel - place content here--&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">StackPanel</span><span style="color: #ff0000;"> x</span><span style="color: #0000ff;">:</span><span style="color: #ff0000;">Name</span><span style="color: #0000ff;">="ContentPanel"</span><span style="color: #ff0000;"> Grid.Row</span><span style="color: #0000ff;">="1"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="12,0,12,0"&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">ComboBox</span><span style="color: #ff0000;"> x</span><span style="color: #0000ff;">:</span><span style="color: #ff0000;">Name</span><span style="color: #0000ff;">="ComboWithTemplate"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="5"</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="450"</span><span style="color: #ff0000;"> Height</span><span style="color: #0000ff;">="50"</span><span style="color: #ff0000;"> HorizontalAlignment</span><span style="color: #0000ff;">="Left"</span></li>
<li><span style="color: #ff0000;">ItemsSource</span><span style="color: #0000ff;">="{</span><span style="color: #a31515;">Binding}</span><span style="color: #0000ff;">"</span><span style="color: #ff0000;"> Foreground</span><span style="color: #0000ff;">="Black"</span><span style="color: #ff0000;"> FontSize</span><span style="color: #0000ff;">="18" &gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">ComboBox.ItemTemplate</span><span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">DataTemplate</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">StackPanel</span><span style="color: #ff0000;"> Orientation</span><span style="color: #0000ff;">="Horizontal"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="2"&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">TextBlock</span><span style="color: #ff0000;"> Text</span><span style="color: #0000ff;">="Artist:"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="2" /&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">TextBlock</span><span style="color: #ff0000;"> Text</span><span style="color: #0000ff;">="{</span><span style="color: #a31515;">Binding</span><span style="color: #ff0000;"> Artist}</span><span style="color: #0000ff;">"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="2" /&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">TextBlock</span><span style="color: #ff0000;"> Text</span><span style="color: #0000ff;">="CD:"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="10,2,0,2" /&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">TextBlock</span><span style="color: #ff0000;"> Text</span><span style="color: #0000ff;">="{</span><span style="color: #a31515;">Binding</span><span style="color: #ff0000;"> Name}</span><span style="color: #0000ff;">"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="2" /&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">StackPanel</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">DataTemplate</span><span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">ComboBox.ItemTemplate</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">ComboBox</span><span style="color: #0000ff;">&gt;</span></li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #008000;">&lt;!--The UI for the details view--&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">StackPanel</span><span style="color: #ff0000;"> x</span><span style="color: #0000ff;">:</span><span style="color: #ff0000;">Name</span><span style="color: #0000ff;">="RecordingDetails"&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">TextBlock</span><span style="color: #ff0000;"> Text</span><span style="color: #0000ff;">="{</span><span style="color: #a31515;">Binding</span><span style="color: #ff0000;"> Artist}</span><span style="color: #0000ff;">" /&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">TextBlock</span><span style="color: #ff0000;"> Text</span><span style="color: #0000ff;">="{</span><span style="color: #a31515;">Binding</span><span style="color: #ff0000;"> Name}</span><span style="color: #0000ff;">" /&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">TextBlock</span><span style="color: #ff0000;"> Text</span><span style="color: #0000ff;">="{</span><span style="color: #a31515;">Binding</span><span style="color: #ff0000;"> ReleaseDate</span><span style="color: #0000ff;">,</span></li>
<li><span style="color: #ff0000;">Converter</span><span style="color: #0000ff;">={</span><span style="color: #a31515;">StaticResource</span><span style="color: #ff0000;"> StringConverter}</span><span style="color: #0000ff;">,</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">ConverterParameter</span><span style="color: #0000ff;">=Released:</span> \\cf1 {0<span style="color: #0000ff;">:</span><span style="color: #a31515;">d\</span>\cf1 }}" /&gt;</li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">StackPanel</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">StackPanel</span><span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #a31515;">...</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">phone</span><span style="color: #0000ff;">:</span><span style="color: #a31515;">PhoneApplicationPage</span><span style="color: #0000ff;">&gt;</span></li>
</ol></div>
</div>
</div>
<p></p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:aaa9b625-826f-4664-bc7f-1687cf6b1558" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">C#</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> <span style="color: #2b91af;">StringFormatter</span> : <span style="color: #ff0000;">IValueConverter</span></li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #008000;">// This converts the value object to the string to display.</span></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// This will work with most simple types.</span></li>
<li><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">object</span> Convert(<span style="color: #0000ff;">object</span> value, <span style="color: #ff0000;">Type</span> targetType,</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">object</span> parameter, System.Globalization.<span style="color: #2b91af;">CultureInfo</span> culture)</li>
<li>{</li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// Retrieve the format string and use it to format the value.</span></li>
<li><span style="color: #0000ff;">string</span> formatString = <span style="color: #ff0000;">parameter</span> <span style="color: #0000ff;">as</span> <span style="color: #0000ff;">string</span>;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">if</span> (!<span style="color: #0000ff;">string</span>.IsNullOrEmpty(formatString))</li>
<li>{</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">string</span>.Format(<span style="color: #ff0000;">culture</span>, formatString, <span style="color: #ff0000;">value</span>);</li>
<li>}</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #008000;">// If the format string is null or empty, simply</span></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// call ToString() on the value.</span></li>
<li><span style="color: #0000ff;">return</span> <span style="color: #ff0000;">value</span>.ToString();</li>
<li style="background: #f3f3f3;">}</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// No need to implement converting back on a one-way binding</span></li>
<li><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">object</span> ConvertBack(<span style="color: #0000ff;">object</span> value, <span style="color: #ff0000;">Type</span> targetType,</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">object</span> parameter, System.Globalization.<span style="color: #2b91af;">CultureInfo</span> culture)</li>
<li>{</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">throw</span> <span style="color: #0000ff;">new</span> <span style="color: #00008b;">NotImplementedException</span>();</li>
<li>}</li>
<li style="background: #f3f3f3;">}</li>
</ol></div>
</div>
</div>
<p></p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:7eb927bc-7d0d-40f7-8ff5-47d30aa189ac" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">Visual Basic</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">Public</span> <span style="color: #0000ff;">Class</span> <span style="color: #2b91af;">StringFormatter</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Implements</span> <span style="color: #ff0000;">IValueConverter</span></li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">' This converts the DateTime object to the string to display.</span></li>
<li><span style="color: #0000ff;">Public</span> <span style="color: #0000ff;">Function</span> Convert(<span style="color: #0000ff;">ByVal</span> value <span style="color: #0000ff;">As</span> <span style="color: #0000ff;">Object</span>, <span style="color: #0000ff;">ByVal</span> targetType <span style="color: #0000ff;">As</span> <span style="color: #2b91af;">Type</span>, _</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">ByVal</span> parameter <span style="color: #0000ff;">As</span> <span style="color: #0000ff;">Object</span>, <span style="color: #0000ff;">ByVal</span> culture <span style="color: #0000ff;">As</span> System.Globalization.<span style="color: #2b91af;">CultureInfo</span>) _</li>
<li><span style="color: #0000ff;">As</span> <span style="color: #0000ff;">Object</span> <span style="color: #0000ff;">Implements</span> <span style="color: #ff0000;">IValueConverter</span>.Convert</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #008000;">' Retrieve the format string and use it to format the value.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Dim</span> formatString <span style="color: #0000ff;">As</span> <span style="color: #0000ff;">String</span> = <span style="color: #0000ff;">TryCast</span>(parameter, <span style="color: #0000ff;">String</span>)</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">If</span> <span style="color: #0000ff;">Not</span> <span style="color: #0000ff;">String</span>.IsNullOrEmpty(formatString) <span style="color: #0000ff;">Then</span></li>
<li><span style="color: #0000ff;">Return</span> <span style="color: #0000ff;">String</span>.Format(culture, formatString, value)</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">If</span></li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">' If the format string is null or empty, simply call ToString()</span></li>
<li><span style="color: #008000;">' on the value.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Return</span> value.ToString()</li>
<li><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Function</span></li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #008000;">' No need to implement converting back on a one-way binding</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Public</span> <span style="color: #0000ff;">Function</span> ConvertBack(<span style="color: #0000ff;">ByVal</span> value <span style="color: #0000ff;">As</span> <span style="color: #0000ff;">Object</span>, <span style="color: #0000ff;">ByVal</span> targetType <span style="color: #0000ff;">As</span> <span style="color: #2b91af;">Type</span>, _</li>
<li><span style="color: #0000ff;">ByVal</span> parameter <span style="color: #0000ff;">As</span> <span style="color: #0000ff;">Object</span>, <span style="color: #0000ff;">ByVal</span> culture <span style="color: #0000ff;">As</span> System.Globalization.<span style="color: #2b91af;">CultureInfo</span>) _</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">As</span> <span style="color: #0000ff;">Object</span> <span style="color: #0000ff;">Implements</span> <span style="color: #ff0000;">IValueConverter</span>.ConvertBack</li>
<li><span style="color: #0000ff;">Throw</span> <span style="color: #0000ff;">New</span> <span style="color: #00008b;">NotImplementedException</span>()</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Function</span></li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Class</span></li>
</ol></div>
</div>
</div>
<p>Un convertisseur (<i>converter</i>) est une classe qui impl&eacute;mente l'interface <a href="http://go.microsoft.com/fwlink/?LinkId=130087">IValueConverter</a>. <b>IValueConverter</b> poss&egrave;de deux m&eacute;thodes : <a href="http://go.microsoft.com/fwlink/?LinkId=130088">Convert</a> et <a href="http://go.microsoft.com/fwlink/?LinkId=130089">ConvertBack</a>. Pour un binding unidirectionnel (one-way) de la source vers la cible, vous n'avez besoin que d'impl&eacute;menter la m&eacute;thode <b>Convert. </b>Le convertisseur dans cet exemple est tr&egrave;s g&eacute;n&eacute;rique. Vous pouvez passer la chaine de formatage comme param&egrave;tre et le convertisseur utilisera la m&eacute;thode <b>Format</b> pour effectuer la conversion. Si aucune chaine de formatage n'est pass&eacute;e alors le convertisseur appelle simplement la m&eacute;thode ToString() sur l'objet.</p>
<p>Une fois que vous impl&eacute;mentez le convertisseur, vous cr&eacute;ez une instance de la classe du convertisseur et dites au binding d'utiliser cette instance. Dans cet exemple, ceci est effectu&eacute; en XAML. Une instance du convertisseur est cr&eacute;&eacute;e en tant que ressource statique et est assign&eacute;e &agrave; une cl&eacute;. La cl&eacute; est utilis&eacute;e lorsque la propri&eacute;t&eacute; Converter est d&eacute;finie par le binding.</p>
<p>Pour plus d'informations sur l'utilisation des convertisseurs, lisez la documentation <a href="http://go.microsoft.com/fwlink/?LinkId=130087">IValueConverter</a> sur MSDN.</p>
<p></p>
<h2>Voir aussi</h2>
<ul>
<li><a href="http://go.microsoft.com/fwlink/?LinkID=111917">Data Binding</a></li>
<li><a href="http://go.microsoft.com/fwlink/?LinkId=111916">XAML Overview</a></li>
<li><a href="http://go.microsoft.com/fwlink/?LinkId=130072">Controls</a></li>
<li><a href="http://go.microsoft.com/fwlink/?LinkId=130090">Controls and Dialog Boxes</a></li>
<li><a href="http://go.microsoft.com/fwlink/?LinkId=111918">Object Positioning and Layout</a></li>
</ul>
<hr />
<p><a href="#sommaire">Cliquez ici pour revenir au sommaire de la liste d&rsquo;articles</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Developpement Windows Phone - partie 17</title>
      <link>https://docs.microsoft.com/archive/blogs/lgmorand/developpement-windows-phone-partie-17</link>
      <pubDate>Tue, 06 Sep 2011 13:17:00 GMT</pubDate>
      <dc:creator><![CDATA[Louis-Guillaume Morand]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/lgmorand/2011/09/06/developpement-windows-phone-partie-17/</guid>
      <description><![CDATA[Graphiques
Cet article fait partie d&rsquo;une s&eacute;rie d&rsquo;articles sur le...]]></description>
      <content:encoded><![CDATA[<h1>Graphiques</h1>
<p>Cet article fait partie d&rsquo;une s&eacute;rie d&rsquo;articles sur le d&eacute;veloppement Windows Phone. Il s&rsquo;agit d&rsquo;une traduction des articles se trouvant <a href="http://create.msdn.com/en-us/education/quickstarts" target="_blank">sur la MSDN</a>.</p>
<h2><a name="sommaire"></a>Sommaire</h2>
<p><strong>Bien d&eacute;buter et fondamentaux</strong></p>
<ul>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-1.aspx" target="_blank">Bien d&eacute;marrer (Hello World)</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-2.aspx" target="_blank">Cr&eacute;er une interface utilisateur pour Windows Phone en XAML</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-3.aspx" target="_blank">Utiliser des contr&ocirc;les</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-4.aspx" target="_blank">Types de contr&ocirc;les</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-5.aspx" target="_blank">Contr&ocirc;les Panorama et Pivot</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-6.aspx" target="_blank">Travailler avec du texte sur le Windows Phone</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-7.aspx" target="_blank">Mise en page sur l&rsquo;&eacute;cran</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-8.aspx" target="_blank">Orientations de l&rsquo;&eacute;cran</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-9.aspx" target="_blank">Saisie tactile</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-10.aspx" target="_blank">Navigation</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-11.aspx" target="_blank">Ex&eacute;cuter votre application en arri&egrave;re-plan (tombstoning)</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-12.aspx" target="_blank">Notifications Push pour le d&eacute;veloppement Windows Phone</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-13.aspx" target="_blank">Publier votre application sur le Marketplace</a></li>
</ul>
<p><strong>Visuels et m&eacute;dia</strong></p>
<ul>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-14.aspx" target="_blank">Images</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-15.aspx" target="_blank">Animations</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-16.aspx" target="_blank">Vid&eacute;o et Audio</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-17.aspx" target="_blank">Graphiques</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-18.aspx" target="_blank">Pinceaux</a></li>
</ul>
<p><strong>Travailler avec les donn&eacute;es</strong></p>
<ul>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-19.aspx" target="_blank">Obtenir des donn&eacute;es dans vos applications Windows Phone</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-20.aspx" target="_blank">Data binding</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-21.aspx" target="_blank">Isolated storage</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-22.aspx" target="_blank">Acc&eacute;der &agrave; un service Web REST</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-23.aspx" target="_blank">Consommer des donn&eacute;es Windows Azure</a></li>
</ul>
<p><strong>Sondes et autres fonctionnalit&eacute;s sp&eacute;cifiques au t&eacute;l&eacute;phone</strong></p>
<ul>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-24.aspx" target="_blank">Lanceurs et choosers</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-25.aspx" target="_blank">D&eacute;tecter des mouvements (acc&eacute;l&eacute;rom&egrave;tres)</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-26.aspx" target="_blank">D&eacute;velopper avec le GPS Windows Phone (Services de localisation)</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-27.aspx" target="_blank">D&eacute;velopper avec l&rsquo;appareil photo du Windows Phone</a></li>
</ul>
<hr />
<h1>Data Binding</h1>
<p>La plupart des applications Windows Phone affichent des donn&eacute;es dans les contr&ocirc;les. Dans de nombreux cas, les donn&eacute;es sont des objets business tels que des actions en bourse, des titres de news ou des images. En plus, vous voulez souvent autoriser l'utilisateur &agrave; s&eacute;lectionner un &eacute;l&eacute;ment depuis une liste puis afficher les d&eacute;tails relatifs &agrave; cet &eacute;l&eacute;ment dans un autre contr&ocirc;le comme par exemple une zone de texte.</p>
<p>Ce tutoriel montre comment lier un contr&ocirc;le &agrave; un simple &eacute;l&eacute;ment et comment lier un contr&ocirc;le de liste &agrave; une collection d'&eacute;l&eacute;ments, De plus, vous verrez au sein de cet article comment personnaliser l'affichage des &eacute;l&eacute;ments, comment impl&eacute;menter une vue d&eacute;taill&eacute;e bas&eacute;e sur une s&eacute;lection et comment convertir les donn&eacute;es avant de les afficher.</p>
<p>Ce tutoriel contient les sections suivantes:</p>
<ul>
<li><a href="#BindingSingleItem">Lier un contr&ocirc;le &agrave; un &eacute;l&eacute;ment unique</a></li>
<li><a href="#BindingToCollection">Lier un contr&ocirc;le &agrave; une collection d'objets</a></li>
<li><a href="#DisplayingItemsWithDataTemplate">Afficher les &eacute;l&eacute;ments dans un contr&ocirc;le en utilisant un data template</a></li>
<li><a href="#AddingDetailsView">Ajouter une vue d&eacute;tails</a></li>
<li><a href="#ConvertingData">Convertir des donn&eacute;es pour les afficher dans des contr&ocirc;les</a></li>
</ul>
<hr />
<h1>Graphiques</h1>
<p>Dans Windows Phone 7, il existe plusieurs options pour cr&eacute;er des formes et les dessiner &agrave; l&rsquo;&eacute;cran. Ce tutoriel introduit les formes telles que les ellipses, les rectangles, les polygones et les chemins. Il se concentre sur la cr&eacute;ation de graphique en utilisant du XAML.</p>
<h5>Remarque</h5>
<p>Si vous faites beaucoup de graphiques, vous voudrez probablement utiliser un outil WYSIWYG tel que <a href="http://www.microsoft.com/expression/products/Blend_Overview.aspx">Expression Blend</a> pour Windows Phone. Un outil WYSIWYG g&eacute;n&egrave;re juste le XAML, et c&rsquo;est pourquoi comprendre le fonctionnement interne du XAML est int&eacute;ressant.</p>
<p>Ce tutoriel contient les sections suivantes:</p>
<ul>
<li><a href="#introduction_graphics">Introduction aux graphiques</a></li>
<li><a href="#create_an_ellipse">Ellipses</a></li>
<li><a href="#create_an_rectangle">Rectangles et contours</a></li>
<li><a href="#create_an_polygon">Polygones</a></li>
<li><a href="#create_an_polyline">Polylines</a></li>
<li><a href="#create_a_path">Paths</a></li>
<li><a href="#graphics_thread">Le thread graphique</a></li>
</ul>
<p></p>
<h2></h2>
<h2><a name="introduction_graphics"></a>Introduction aux graphiques</h2>
<p>Il existe deux ensembles de classes qui d&eacute;finissent une r&eacute;gion d&rsquo;espace : <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape%28VS.95%29.aspx">Shape</a> et <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.geometry%28VS.95%29.aspx">Geometry</a>. La principale diff&eacute;rence entre ces classes est qu&rsquo;un <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape%28VS.95%29.aspx">Shape</a> a un pinceau (brush) associ&eacute; et peut &ecirc;tre affich&eacute; &agrave; l&rsquo;&eacute;cran, tandis qu&rsquo;un objet <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.geometry%28VS.95%29.aspx">Geometry</a> d&eacute;finit simplement une r&eacute;gion d&rsquo;espace et n&rsquo;est pas affich&eacute;. Vous pouvez voir un <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape%28VS.95%29.aspx">Shape</a> comme un <a href="http://msdn.microsoft.com/en-us/library/system.windows.uielement%28v=VS.95%29.aspx">UIElement</a> avec ses limites d&eacute;finies par un <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.geometry%28VS.95%29.aspx">Geometry</a>. Ce tutoriel ne parlera que des classes <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape%28VS.95%29.aspx">Shape</a>.</p>
<p>Les diff&eacute;rentes classes <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape%28VS.95%29.aspx">Shape</a> sont <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.line%28VS.95%29.aspx">Line</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.ellipse%28VS.95%29.aspx">Ellipse</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.rectangle%28VS.95%29.aspx">Rectangle</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.polygon%28VS.95%29.aspx">Polygon</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.polyline%28VS.95%29.aspx">Polyline</a>, et <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.Path%28VS.95%29.aspx">Path</a>. <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.Path%28VS.95%29.aspx">Path</a> est int&eacute;ressant dans le sens o&ugrave; il permet de d&eacute;finir une forme de votre choix.</p>
<p>Pour qu&rsquo;un objet <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape%28VS.95%29.aspx">Shape</a> soit affich&eacute; &agrave; l&rsquo;&eacute;cran, un objet <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.brush%28VS.95%29.aspx">Brush</a> doit lui &ecirc;tre associ&eacute;. La propri&eacute;t&eacute; <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape.fill%28VS.95%29.aspx">Fill</a> du <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape%28VS.95%29.aspx">Shape</a> est d&eacute;finie sur l&rsquo;objet <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.brush%28VS.95%29.aspx">Brush</a> d&eacute;sir&eacute;. Les diff&eacute;rents types de pinceaux de Silverlight pour Windows Phone sont: <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.solidcolorbrush%28VS.95%29.aspx">SolidColorBrush</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.lineargradientbrush%28VS.95%29.aspx">LinearGradientBrush</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.radialgradientbrush%28VS.95%29.aspx">RadialGradientBrush</a>, et <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imagebrush%28VS.95%29.aspx">ImageBrush</a>. <br />Pour plus d&rsquo;informations sur les classes <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape%28VS.95%29.aspx">Shape</a> et <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.geometry%28VS.95%29.aspx">Geometry</a>, lisez les sujets suivants sur MSDN:</p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/cc189073%28VS.95%29.aspx">Shapes and Drawing</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/cc189068%28VS.95%29.aspx">Geometries</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/cc189041%28VS.95%29.aspx">Path Markup Syntax</a></li>
</ul>
<p></p>
<h2></h2>
<h2><a name="create_an_ellipse"></a>Ellipses</h2>
<p>Pour cr&eacute;er une <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.ellipse%28VS.95%29.aspx">Ellipse</a> basique, sp&eacute;cifiez simplement les propri&eacute;t&eacute;s <a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.width%28VS.95%29.aspx">Width</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.height%28VS.95%29.aspx">Height</a>, et un <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.brush%28VS.95%29.aspx">Brush</a> pour la propri&eacute;t&eacute; <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape.fill%28VS.95%29.aspx">Fill</a>.</p>
<p>L&rsquo;exemple suivant cr&eacute;&eacute; une <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.ellipse%28VS.95%29.aspx">Ellipse</a> avec une largeur (<a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.width%28VS.95%29.aspx">Width</a>) de 300 pixels, une hauteur (<a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.height%28VS.95%29.aspx">Height</a>) de 300 pixels, et utilise un objet SBlue de type <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.solidcolorbrush%28VS.95%29.aspx">SolidColorBrush</a> pour sa propri&eacute;t&eacute; <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape.fill%28VS.95%29.aspx">Fill</a>.</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:faa0e026-dd9b-4c5a-9416-095c19dcf056" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">XAML</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">Ellipse</span><span style="color: #ff0000;"> Fill</span><span style="color: #0000ff;">="Blue"</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="300"</span></li>
<li><span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="300"&gt;</span></li>
</ol></div>
</div>
</div>
<p></p>
<p><img alt="Displays an Ellipse" src="http://create.msdn.com/assets/cms/images/quickstarts/QuickStart_Graphics_Ellipse.png" /></p>
<h2><a name="create_an_rectangle"></a>Rectangles et contours</h2>
<p>Silverlight vous autorise &agrave; arrondir les coins d&rsquo;un <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.rectangle%28VS.95%29.aspx">Rectangle</a>. Pour cr&eacute;er des coins arrondis, specifies une valeur pour les propri&eacute;t&eacute;s <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.rectangle.radiusx%28VS.95%29.aspx">RadiusX</a> et <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.rectangle.radiusy%28VS.95%29.aspx">RadiusY</a>. Ces propri&eacute;t&eacute;s sp&eacute;cifient les axes X et Y d&rsquo;une ellipse qui d&eacute;finit la courbe des coins. La valeur maximum de la propri&eacute;t&eacute; <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.rectangle.radiusx%28VS.95%29.aspx">RadiusX</a> est la valeur de <a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.width%28VS.95%29.aspx">Width</a> divis&eacute;e par deux et la valeur maximum de la propri&eacute;t&eacute; <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.rectangle.radiusy%28VS.95%29.aspx">RadiusY</a> est celle de <a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.height%28VS.95%29.aspx">Height</a> divis&eacute;e par deux.</p>
<p>Toutes les classes <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape%28VS.95%29.aspx">Shape</a> ont des propri&eacute;t&eacute;s <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape.stroke%28VS.95%29.aspx">Stroke</a> et <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape.strokethickness%28VS.95%29.aspx">StrokeThickness</a>. <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape.stroke%28VS.95%29.aspx">Stroke</a> sp&eacute;cifie le pinceau (<a href="http://msdn.microsoft.com/en-us/library/system.windows.media.brush%28VS.95%29.aspx">Brush</a>) qui est utilis&eacute; pour peindre la bordure de la forme. <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape.strokethickness%28VS.95%29.aspx">StrokeThickness</a> sp&eacute;cifie l'&eacute;paisseur de cette bordure.</p>
<p>Remarque</p>
<p>Un objet <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.line%28VS.95%29.aspx">Line</a> affiche seulement un objet <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape.stroke%28VS.95%29.aspx">Stroke</a>, et non l&rsquo;objet <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape.fill%28VS.95%29.aspx">Fill</a>, car il n'a pas d'espace int&eacute;rieur. Pour afficher une ligne (<a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.line%28VS.95%29.aspx">Line</a>), assurez-vous que les propri&eacute;t&eacute;s <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape.stroke%28VS.95%29.aspx">Stroke</a> et <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape.strokethickness%28VS.95%29.aspx">StrokeThickness</a> sont sp&eacute;cifi&eacute;es.</p>
<p>Dans l'exemple suivant, on cr&eacute;&eacute; un <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.rectangle%28VS.95%29.aspx">Rectangle</a> avec une largeur <a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.width%28VS.95%29.aspx">Width</a> de 100 et une hauteur <a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.height%28VS.95%29.aspx">Height</a> de 50. Il utilise un pinceau <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.solidcolorbrush%28VS.95%29.aspx">SolidColorBrush</a> pour le remplissage <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape.fill%28VS.95%29.aspx">Fill</a> et un pinceau noir pour le contour <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape.stroke%28VS.95%29.aspx">Stroke</a>. La propri&eacute;t&eacute; <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape.strokethickness%28VS.95%29.aspx">StrokeThickness</a> est d&eacute;finie sur 3 pixels et les propri&eacute;t&eacute;s <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.rectangle.radiusx%28VS.95%29.aspx">RadiusX</a> et <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.rectangle.radiusy%28VS.95%29.aspx">RadiusY</a> sur 10, ce qui donne au <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.rectangle%28VS.95%29.aspx">Rectangle</a> des coins arrondis. <br />L'image suivante montre un <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.rectangle%28VS.95%29.aspx">Rectangle</a> avec des coins arrondis affich&eacute;s sur un Windows Phone.</p>
<p><object data="data:application/x-silverlight-2," type="application/x-silverlight-2" autoupdate="true" height="380" width="600"><param name="source" value="http://create.msdn.com/assets/cms/docs/QuickstartsXAP/Graphics_RectangleInteractive.xap" /><param name="minRuntimeVersion" value="3.0.40624.0" /><param name="background" value="White" /><param name="autoUpgrade" value="true" /><a href="http://go.microsoft.com/fwlink/?LinkID=149156&amp;v=3.0.40624.0" style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style: none;" /> </a> </object></p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:158c447e-4085-4dc1-ab25-7f031a5f081c" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">XAML</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">Rectangle</span><span style="color: #ff0000;"> Fill</span><span style="color: #0000ff;">="SteelBlue"</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">Height</span><span style="color: #0000ff;">="275"</span></li>
<li><span style="color: #ff0000;">Width</span><span style="color: #0000ff;">="350"</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">Stroke</span><span style="color: #0000ff;">="AliceBlue"</span></li>
<li><span style="color: #ff0000;">StrokeThickness</span><span style="color: #0000ff;">="15"</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">RadiusX</span><span style="color: #0000ff;">="40"</span></li>
<li><span style="color: #ff0000;">RadiusY</span><span style="color: #0000ff;">="30"&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">Rectangle</span><span style="color: #0000ff;">&gt;</span></li>
</ol></div>
</div>
</div>
<p></p>
<p><img alt="Displays a Rectangle" src="http://create.msdn.com/assets/cms/images/quickstarts/QuickStart_Graphics_Rectangle.png" /></p>
<h2><a name="create_an_polygon"></a>Polygones</h2>
<p>Un <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.polygon%28VS.95%29.aspx">Polygon</a> est une forme avec une limitation d&eacute;finie par un nombre arbitraire de points. La limitation est cr&eacute;&eacute;e en connectant une ligne entre un point et le suivant, le dernier point &eacute;tant reli&eacute; au tout premier. La propri&eacute;t&eacute; <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.polygon.points%28VS.95%29.aspx">Points</a> d&eacute;finie la collection de points qui forment cette limitation. En XAML, vous d&eacute;finissez les points avec une liste s&eacute;par&eacute;e par des points. En code, vous utilisez un objet <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.pointcollection%28VS.95%29.aspx">PointCollection</a>, collection &agrave; laquelle vous ajoutez les points un par un.</p>
<p>L'exemple suivant cr&eacute;&eacute; un <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.polygon%28VS.95%29.aspx">Polygon</a> avec quatre points d&eacute;finis sur (10,200), (60,140), (130,140), et (180,200). Il utilise un pinceau bleu (<a href="http://msdn.microsoft.com/en-us/library/system.windows.media.solidcolorbrush%28VS.95%29.aspx">SolidColorBrush</a>) pour son remplissage (<a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape.fill%28VS.95%29.aspx">Fill</a>). Aucun <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape.stroke%28VS.95%29.aspx">Stroke</a> n'est d&eacute;fini et il est donc possible d'arranger les points pour que rien ne soit affich&eacute;. Si un <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape.stroke%28VS.95%29.aspx">Stroke</a> est d&eacute;fini, au moins une ligne ou un point aussi fin que le <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape.stroke%28VS.95%29.aspx">Stroke</a> est d&eacute;fini. Utilisez les sliders dans l'exemple pour exp&eacute;rimenter avec les coordonn&eacute;es des diff&eacute;rents points. Notez &eacute;galement que si vous cochez la case <b>Stroke</b> le dernier point est connect&eacute; au premier.</p>
<p></p>
<h2>&nbsp;<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" autoupdate="true" height="380" width="600"><param name="source" value="http://create.msdn.com/assets/cms/docs/QuickstartsXAP/Graphics_PolygonInteractive.xap" /><param name="minRuntimeVersion" value="3.0.40624.0" /><param name="background" value="White" /><param name="autoUpgrade" value="true" /><a href="http://go.microsoft.com/fwlink/?LinkID=149156&amp;v=3.0.40624.0" style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style: none;" /> </a> </object></h2>
<h2><a name="create_an_polyline"></a>Polylines</h2>
<p>Un objet <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.polyline%28VS.95%29.aspx">Polyline</a> est similaire &agrave; un <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.polygon%28VS.95%29.aspx">Polygon</a> dont les limites de la forme sont d&eacute;finies par une s&eacute;rie de point. La principale diff&eacute;rence entre un <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.polyline%28VS.95%29.aspx">Polyline</a> et un <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.polygon%28VS.95%29.aspx">Polygon</a> est que le dernier point d'un <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.polyline%28VS.95%29.aspx">Polyline</a> n'est pas connect&eacute; au premier point. La propri&eacute;t&eacute; <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape.fill%28VS.95%29.aspx">Fill</a> d'un <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.polyline%28VS.95%29.aspx">Polyline</a> peint toujours l'int&eacute;rieur de la forme m&ecirc;me si les extr&eacute;mit&eacute;s des limites (ou <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape.stroke%28VS.95%29.aspx">Stroke</a>) ne se touchent pas.</p>
<p>Comme avec un <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.polygon%28VS.95%29.aspx">Polygon</a>, la propri&eacute;t&eacute; <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.polygon.points%28VS.95%29.aspx">Points</a> d&eacute;finie la collection de points qui forment les limitations. En XAML, vous d&eacute;finissez les points avec une liste s&eacute;par&eacute;e par des virgules. En code, vous utilisez un objet <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.pointcollection%28VS.95%29.aspx">PointCollection</a> dans lequel vous ajoutez chaque <a href="http://msdn.microsoft.com/en-us/library/system.windows.point%28VS.95%29.aspx">Point</a> pour former la collection.</p>
<p>L'exemple suivant cr&eacute;&eacute; un <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.polyline%28VS.95%29.aspx">Polyline</a> avec quatre points d&eacute;finis sur (10,200), (60,140), (130,140), et (180,200). La propri&eacute;t&eacute; <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape.fill%28VS.95%29.aspx">Fill</a> n'est pas d&eacute;finie mais un <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape.stroke%28VS.95%29.aspx">Stroke</a> l'est. Notez que le dernier et le premier point ne sont pas connect&eacute;s comme ils le sont pour un <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.polygon%28VS.95%29.aspx">Polygon</a>. Utilisez les slides dans cet exemple pour exp&eacute;rimenter avec les coordonn&eacute;es des diff&eacute;rents points. Comparez les diff&eacute;rences entre un <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.polyline%28VS.95%29.aspx">Polyline</a> et <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.polygon%28VS.95%29.aspx">Polygon</a> lorsque les cases <b>Fill</b> et <b>Stroke</b> sont coch&eacute;es</p>
<p></p>
<h2>&nbsp;<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" autoupdate="true" height="380" width="600"><param name="source" value="http://create.msdn.com/assets/cms/docs/QuickstartsXAP/Graphics_PolylineInteractive.xap" /><param name="minRuntimeVersion" value="3.0.40624.0" /><param name="background" value="White" /><param name="autoUpgrade" value="true" /><a href="http://go.microsoft.com/fwlink/?LinkID=149156&amp;v=3.0.40624.0" style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style: none;" /> </a> </object></h2>
<h2><a name="create_a_path"></a>Paths</h2>
<p>Un objet <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.path%28VS.95%29.aspx">Path</a> est la forme (<a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape%28VS.95%29.aspx">Shape</a>) la plus versatile parce qu&rsquo;elle vous permet de d&eacute;finir une g&eacute;om&eacute;trie arbitraire. Pourtant, avec cette libert&eacute; vient &eacute;galement une complexit&eacute; accrue. Cette section vous montre comment cr&eacute;er un <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.path%28VS.95%29.aspx">Path</a> basic en XAML. Pour voir cet objet en profondeur, lisez les articles MSDN <a href="http://msdn.microsoft.com/en-us/library/cc189041%28VS.95%29.aspx">Path Markup Syntax</a> et <a href="http://msdn.microsoft.com/en-us/library/cc189073%28VS.95%29.aspx">Shapes and Drawing</a>.</p>
<p>La g&eacute;om&eacute;trie d&rsquo;un chemin est d&eacute;finie avec la propri&eacute;t&eacute; <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.path.data%28VS.95%29.aspx">Data</a>. La propri&eacute;t&eacute; <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.path.data%28VS.95%29.aspx">Data</a> peut &ecirc;tre d&eacute;finie sur un objet <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.geometry%28VS.95%29.aspx">Geometry</a> ou en XAML. Pour d&eacute;finir un chemin en XAML, vous utilisez la syntaxe de "<i>path markup</i>".</p>
<p>L'exemple suivant cr&eacute;&eacute; un <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.path%28VS.95%29.aspx">Path</a> qui est bas&eacute; sur une courbe de Bezier et un segment. L'attribut <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.path.data%28VS.95%29.aspx">Data</a> commence avec la commande Move, indiqu&eacute; par un M, qui &eacute;tablit un point de d&eacute;part pour le path. La lettre majuscule M indique une position absolue pour le nouveau point courant. La lettre majuscule M indique une position absolue du point courant. Un &ldquo;m&rdquo; minuscule indique une position relative. Le premier segment est une courbe de B&eacute;zier cubique qui commence &agrave; (100,200) et finit &agrave; (400,175), et qui est dessin&eacute;e en utilisant les points de contr&ocirc;le (100,25) et (400,350). Ce segment est indiqu&eacute; par la commande C dans les attributs de <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.path.data%28VS.95%29.aspx">Data</a>. Une fois encore, la lettre majuscule C indique un chemin en position absolue, la lettre minuscule indique un chemin relatif.</p>
<p>Le second segment commence avec une commande (H) de ligne horizontale, qui signifie une ligne dessin&eacute;e &agrave; partir de la fin du pr&eacute;c&eacute;dent segment (400,175) vers un nouveau point (280,175). Parce qu'il s'agit d'une commande de ligne horizontale, la valeur sp&eacute;cifi&eacute;e est une coordonn&eacute;e X (ordonn&eacute;e).</p>
<h5>Remarque</h5>
<p>Les param&egrave;tres de donn&eacute;es des path sont sensibles &agrave; la casse.</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:a13eee2a-a0ac-40f8-b5a4-d34769c339e6" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">XAML</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">Path</span><span style="color: #ff0000;"> Stroke</span><span style="color: #0000ff;">="DarkGoldenRod"</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">StrokeThickness</span><span style="color: #0000ff;">="3"</span></li>
<li><span style="color: #ff0000;">Data</span><span style="color: #0000ff;">="M 100,200 C 100,25 400,350 400,175 H 280" /</span></li>
</ol></div>
</div>
</div>
<p>L'image suivante montre le Path, affich&eacute; dans un Windows Phone.</p>
<p></p>
<p><img alt="Displays a Path" src="http://create.msdn.com/assets/cms/images/quickstarts/QuickStart_Graphics_Path.png" /></p>
<h2><a name="graphics_thread"></a>Le thread graphique</h2>
<p>Une des diff&eacute;rences entre Silverlight pour Windows Phone et Silverlight pour navigateur Web est que les graphiques du t&eacute;l&eacute;phone (et quelques animations) s'ex&eacute;cutent dans un thread diff&eacute;rent. Pour la plupart des sc&eacute;narii, vous n'aurez pas besoin de vous en soucier car le syst&egrave;me le fait pour vous. Mais si votre application poss&egrave;de un grand nombre de graphiques, il existe des consid&eacute;rations de design et de performance qu'il vous faudra prendre en compte.</p>
<p>Pour plus d'informations &agrave; propos du thread de composition, lisez la MSDN <span style="text-decoration: underline;"><a href="http://msdn.microsoft.com/en-us/library/ff602285%28v=VS.95%29.aspx">Graphics in Silverlight for Windows Phone</a></span>.</p>
<p>Pour plus d&rsquo;informations sur les performances lisez l'article <a href="http://msdn.microsoft.com/en-us/library/ff967560%28v=VS.92%29.aspx">Performance Considerations in Applications for Windows Phone</a>.</p>
<p></p>
<h2></h2>
<h2>Voir aussi</h2>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/cc189073%28VS.95%29.aspx">Shapes and Drawing</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/cc189068%28VS.95%29.aspx">Geometries</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/cc189041%28VS.95%29.aspx">Path Markup Syntax</a></li>
</ul>
<hr />
<p><a href="#sommaire">Cliquez ici pour revenir au sommaire de la liste d&rsquo;articles</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Developpement Windows Phone - partie 14</title>
      <link>https://docs.microsoft.com/archive/blogs/lgmorand/developpement-windows-phone-partie-14</link>
      <pubDate>Tue, 06 Sep 2011 13:14:00 GMT</pubDate>
      <dc:creator><![CDATA[Louis-Guillaume Morand]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/lgmorand/2011/09/06/developpement-windows-phone-partie-14/</guid>
      <description><![CDATA[Images
Cet article fait partie d&rsquo;une s&eacute;rie d&rsquo;articles sur le...]]></description>
      <content:encoded><![CDATA[<h1>Images</h1>
<p>Cet article fait partie d&rsquo;une s&eacute;rie d&rsquo;articles sur le d&eacute;veloppement Windows Phone. Il s&rsquo;agit d&rsquo;une traduction des articles se trouvant <a href="http://create.msdn.com/en-us/education/quickstarts" target="_blank">sur la MSDN</a>.</p>
<h2><a name="sommaire"></a>Sommaire</h2>
<p><strong>Bien d&eacute;buter et fondamentaux</strong></p>
<ul>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-1.aspx" target="_blank">Bien d&eacute;marrer (Hello World)</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-2.aspx" target="_blank">Cr&eacute;er une interface utilisateur pour Windows Phone en XAML</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-3.aspx" target="_blank">Utiliser des contr&ocirc;les</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-4.aspx" target="_blank">Types de contr&ocirc;les</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-5.aspx" target="_blank">Contr&ocirc;les Panorama et Pivot</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-6.aspx" target="_blank">Travailler avec du texte sur le Windows Phone</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-7.aspx" target="_blank">Mise en page sur l&rsquo;&eacute;cran</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-8.aspx" target="_blank">Orientations de l&rsquo;&eacute;cran</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-9.aspx" target="_blank">Saisie tactile</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-10.aspx" target="_blank">Navigation</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-11.aspx" target="_blank">Ex&eacute;cuter votre application en arri&egrave;re-plan (tombstoning)</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-12.aspx" target="_blank">Notifications Push pour le d&eacute;veloppement Windows Phone</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-13.aspx" target="_blank">Publier votre application sur le Marketplace</a></li>
</ul>
<p><strong>Visuels et m&eacute;dia</strong></p>
<ul>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-14.aspx" target="_blank">Images</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-15.aspx" target="_blank">Animations</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-16.aspx" target="_blank">Vid&eacute;o et Audio</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-17.aspx" target="_blank">Graphiques</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-18.aspx" target="_blank">Pinceaux</a></li>
</ul>
<p><strong>Travailler avec les donn&eacute;es</strong></p>
<ul>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-19.aspx" target="_blank">Obtenir des donn&eacute;es dans vos applications Windows Phone</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-20.aspx" target="_blank">Data binding</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-21.aspx" target="_blank">Isolated storage</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-22.aspx" target="_blank">Acc&eacute;der &agrave; un service Web REST</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-23.aspx" target="_blank">Consommer des donn&eacute;es Windows Azure</a></li>
</ul>
<p><strong>Sondes et autres fonctionnalit&eacute;s sp&eacute;cifiques au t&eacute;l&eacute;phone</strong></p>
<ul>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-24.aspx" target="_blank">Lanceurs et choosers</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-25.aspx" target="_blank">D&eacute;tecter des mouvements (acc&eacute;l&eacute;rom&egrave;tres)</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-26.aspx" target="_blank">D&eacute;velopper avec le GPS Windows Phone (Services de localisation)</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-27.aspx" target="_blank">D&eacute;velopper avec l&rsquo;appareil photo du Windows Phone</a></li>
</ul>
<hr />
<h1>Data Binding</h1>
<p>La plupart des applications Windows Phone affichent des donn&eacute;es dans les contr&ocirc;les. Dans de nombreux cas, les donn&eacute;es sont des objets business tels que des actions en bourse, des titres de news ou des images. En plus, vous voulez souvent autoriser l'utilisateur &agrave; s&eacute;lectionner un &eacute;l&eacute;ment depuis une liste puis afficher les d&eacute;tails relatifs &agrave; cet &eacute;l&eacute;ment dans un autre contr&ocirc;le comme par exemple une zone de texte.</p>
<p>Ce tutoriel montre comment lier un contr&ocirc;le &agrave; un simple &eacute;l&eacute;ment et comment lier un contr&ocirc;le de liste &agrave; une collection d'&eacute;l&eacute;ments, De plus, vous verrez au sein de cet article comment personnaliser l'affichage des &eacute;l&eacute;ments, comment impl&eacute;menter une vue d&eacute;taill&eacute;e bas&eacute;e sur une s&eacute;lection et comment convertir les donn&eacute;es avant de les afficher.</p>
<p>Ce tutoriel contient les sections suivantes:</p>
<ul>
<li><a href="#BindingSingleItem">Lier un contr&ocirc;le &agrave; un &eacute;l&eacute;ment unique</a></li>
<li><a href="#BindingToCollection">Lier un contr&ocirc;le &agrave; une collection d'objets</a></li>
<li><a href="#DisplayingItemsWithDataTemplate">Afficher les &eacute;l&eacute;ments dans un contr&ocirc;le en utilisant un data template</a></li>
<li><a href="#AddingDetailsView">Ajouter une vue d&eacute;tails</a></li>
<li><a href="#ConvertingData">Convertir des donn&eacute;es pour les afficher dans des contr&ocirc;les</a></li>
</ul>
<hr />
<h1>Images</h1>
<p>Dans Silverlight pour Windows Phone 7, vous avez plusieurs options pour afficher des images telles que des photos ou des diagrammes. Ce tutoriel d&eacute;crit comment int&eacute;grer des images dans vos applications Windows Phone.</p>
<p>Ce tutoriel contient les sections suivantes:</p>
<ul>
<li><a href="#image_and_imagebrush">Image et ImageBrush</a></li>
<li><a href="#stretching_an_image">Etirer une image</a></li>
<li><a href="#cropping_an_image">Rogner une image</a></li>
<li><a href="#applying_an_opacitymask">Appliquer un masque d&rsquo;opacit&eacute;</a></li>
<li><a href="#creating_WriteableBitmaps">Cr&eacute;er des WriteableBitmaps</a></li>
</ul>
<p></p>
<h2></h2>
<h2><a name="image_and_imagebrush"></a>Image et ImageBrush</h2>
<p>Pour afficher une image, vous pouvez utiliser au choix un objet <a href="http://go.microsoft.com/fwlink/?LinkId=129800">Image</a> ou un objet <a href="http://go.microsoft.com/fwlink/?LinkId=129801">ImageBrush</a>. L&rsquo;exemple suivant montre comment afficher une image nomm&eacute;e licorige.jpg en utilisant un objet <a href="http://go.microsoft.com/fwlink/?LinkId=129800">Image</a>.</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6d39ea5f-7ad5-4fdc-bb5e-edd5b32ec55b" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">XAML</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">Image</span><span style="color: #ff0000;"> Source</span><span style="color: #0000ff;">="licorice.JPG" /&gt;</span></li>
</ol></div>
</div>
</div>
<p>La capture suivante montre le r&eacute;sultat dans l&rsquo;&eacute;mulateur.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/6064.image_thumb1_6567256E.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/6064.image_5F00_thumb1_5F00_6567256E.png"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image_thumb1" alt="image_thumb1" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/6545.image_thumb1_thumb_4909BD81.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/6545.image_5F00_thumb1_5F00_thumb_5F00_4909BD81.png" border="0" height="469" width="260" /></a></p>
<p>Dans cet exemple, la propri&eacute;t&eacute; <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.image.source%28v=VS.95%29.aspx">Source</a> sp&eacute;cifie l&rsquo;emplacement de l&rsquo;image que vous voulez afficher. Vous pouvez sp&eacute;cifier la <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.image.source%28v=VS.95%29.aspx">Source</a> avec un chemin absolu (par exemple, <a href="http://contoso.com/myPicture.jpg">http://contoso.com/myPicture.jpg</a>) ou en sp&eacute;cifiant l&rsquo;URL d&rsquo;un fichier qui est inclut dans le fichier XAP. Pour ajouter une image &agrave; votre application, effectuez les op&eacute;rations suivantes dans Visual Studio:</p>
<ol>
<li>Dans le menu <b>Projet</b>, s&eacute;lectionnez <b>Ajouter un &eacute;l&eacute;ment existant</b>.</li>
<li>S&eacute;lectionnez le fichier image et cliquez sur <b>Ajouter</b>.</li>
<li>Dans l&rsquo;explorateur de solution, s&eacute;lectionnez l&rsquo;image qui vient d&rsquo;&ecirc;tre ajout&eacute;e.</li>
<li>Dans la fen&ecirc;tre des propri&eacute;t&eacute;s, changez la propri&eacute;t&eacute; <b>Build Action</b> sur <b>Content</b>.</li>
</ol>
<p>Ainsi, lorsque l&rsquo;application est compil&eacute;e, le fichier image est inclut dans le XAP.</p>
<h5>Remarque</h5>
<p>Silverlight pour Windows Phone ne supporte pas tous les formats d&rsquo;images. La classe <a href="http://go.microsoft.com/fwlink/?LinkId=129901">BitmapImage</a> peut &ecirc;tre utilis&eacute;e pour r&eacute;f&eacute;rence des images dans les formats JPEG et PNG. Pour plus d&rsquo;informations sur les sources d&rsquo;images ou les formats qui peuvent &ecirc;tre utilis&eacute;s pour un objet <a href="http://go.microsoft.com/fwlink/?LinkId=129800">Image</a>, regardez <a href="http://go.microsoft.com/fwlink/?LinkId=129901">BitmapImage</a>.</p>
<p>L&rsquo;objet <a href="http://go.microsoft.com/fwlink/?LinkId=129801">ImageBrush</a> vous autorise &agrave; utiliser une image pour peindre une zone qui prend un objet <a href="http://go.microsoft.com/fwlink/?LinkId=129807">Brush</a>. Par exemple, <a href="http://go.microsoft.com/fwlink/?LinkId=129801">ImageBrush</a> peut &ecirc;tre utilis&eacute; comme valeur pour la propri&eacute;t&eacute; <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.panel.background%28v=VS.95%29.aspx">Background</a> d'un <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.panel%28VS.95%29.aspx">Panel</a>. Pour plus d'informations sur les pinceaux, lisez l'article suivant <a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-18.aspx" target="_blank">Pinceaux</a>.</p>
<p>Voici un exemple qui montre comment l'image <i>licorice</i> est peinte au sein d'un texte</p>
<p></p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:2c5f0fcd-6964-43d4-9acf-69d28652e5d0" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">XAML</div>
<div style="background: #ddd; max-height: 500px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #008000;">&lt;!-- TextBlock with an image brush applied to the text. --&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">TextBlock</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="20"</span></li>
<li><span style="color: #ff0000;">Text</span><span style="color: #0000ff;">="LICORICE"</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">FontFamily</span><span style="color: #0000ff;">="Verdana"</span></li>
<li><span style="color: #ff0000;">FontSize</span><span style="color: #0000ff;">="80"</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">FontWeight</span><span style="color: #0000ff;">="Bold"&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">TextBlock.Foreground</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">ImageBrush</span><span style="color: #ff0000;"> ImageSource</span><span style="color: #0000ff;">="licorice.JPG"/&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">TextBlock.Foreground</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">TextBlock</span><span style="color: #0000ff;">&gt;</span></li>
</ol></div>
</div>
</div>
<p>Voici le r&eacute;sultat dans l'&eacute;mulateur.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/7534.image_thumb3_419DD807.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/7534.image_5F00_thumb3_5F00_419DD807.png"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image_thumb3" alt="image_thumb3" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/4314.image_thumb3_thumb_717879C8.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/4314.image_5F00_thumb3_5F00_thumb_5F00_717879C8.png" border="0" height="430" width="238" /></a></p>
<h2></h2>
<h2><a name="stretching_an_image"></a>Etirer une Image</h2>
<p>Si vous ne d&eacute;finissez pas les valeurs <a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.width%28v=VS.95%29.aspx">Width</a> ou <a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.height%28v=VS.95%29.aspx">Height</a> d'une <a href="http://go.microsoft.com/fwlink/?LinkId=129800">Image</a>, alors elle sera affich&eacute;e avec les dimensions de l'image sp&eacute;cifi&eacute;e par la propri&eacute;t&eacute; <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.image.source%28v=VS.95%29.aspx">Source</a>. Le fait de d&eacute;finir les propri&eacute;t&eacute;s <a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.width%28v=VS.95%29.aspx">Width</a> et <a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.height%28v=VS.95%29.aspx">Height</a> cr&eacute;&eacute; une zone rectangulaire dans laquelle se trouvera l'image. Vous pouvez sp&eacute;cifier comment l'image remplira cette zone en utilisant la propri&eacute;t&eacute; <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.image.stretch%28v=VS.95%29.aspx">Stretch</a> qui accepte les valeurs suivantes:</p>
<ul>
<li><b>None</b>: l'image ne s'&eacute;tend pas pour remplir les dimensions de sortie.</li>
<li><b>Uniform</b>: l'image est d&eacute;form&eacute;e pour remplir les dimensions de la zone. Mais le ratio d'affichage est pr&eacute;serv&eacute;. C'est la valeur par d&eacute;faut.</li>
<li><b>UniformToFill</b>: L'image est agrandie pour remplir compl&egrave;tement la zone mais pr&eacute;serve son ratio. (une partie de l'image peut alors ne pas &ecirc;tre visible).</li>
<li><b>Fill</b>: L'image est d&eacute;form&eacute;e pour remplir la zone. Le ratio peut alors ne pas &ecirc;tre respect&eacute; et l'image s'en retrouve potentiellement avec un ratio totalement diff&eacute;rent que celui de son image source.</li>
</ul>
<p>L'illustration suivante montre les diff&eacute;rents param&eacute;trages possibles de la propri&eacute;t&eacute; <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.stretch%28v=VS.95%29.aspx">Stretch</a>.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/8117.image_thumb5_683C3E87.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/8117.image_5F00_thumb5_5F00_683C3E87.png"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image_thumb5" alt="image_thumb5" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/0601.image_thumb5_thumb_2AEB63F3.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/0601.image_5F00_thumb5_5F00_thumb_5F00_2AEB63F3.png" border="0" height="215" width="573" /></a></p>
<h2></h2>
<h2><a name="cropping_an_image"></a>Rogner une Image</h2>
<p>Vous pouvez utiliser la propri&eacute;t&eacute; <a href="http://msdn.microsoft.com/en-us/library/system.windows.uielement.clip%28v=VS.95%29.aspx">Clip</a> pour d&eacute;tourer une zone d&rsquo;une <a href="http://go.microsoft.com/fwlink/?LinkId=129800">Image</a>. Vous d&eacute;finissez la propri&eacute;t&eacute; <a href="http://msdn.microsoft.com/en-us/library/system.windows.uielement.clip%28v=VS.95%29.aspx">Clip</a> sur un objet <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.geometry%28VS.95%29.aspx">Geometry</a>, ce qui vous permet de d&eacute;couper une vari&eacute;t&eacute; de formes g&eacute;om&eacute;triques dans votre <a href="http://go.microsoft.com/fwlink/?LinkId=129800">Image</a> (par exemple, une ellipse, ligne ou un chemin complexe). Pour plus d&rsquo;informations sur l&rsquo;utilisation des g&eacute;om&eacute;tries, lisez la pr&eacute;sentation des <a href="http://go.microsoft.com/fwlink/?LinkId=129811">G&eacute;om&eacute;tries</a> sur MSDN.</p>
<p>L&rsquo;exemple suivant montre comment utiliser un <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.ellipsegeometry%28v=VS.95%29.aspx">EllipseGeometry</a> comme r&eacute;gion de d&eacute;coupage pour une <a href="http://go.microsoft.com/fwlink/?LinkId=129800">Image</a>. Dans cet exemple, un objet <a href="http://go.microsoft.com/fwlink/?LinkId=129800">Image</a> est d&eacute;fini avec la propri&eacute;t&eacute; <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.image.source%28v=VS.95%29.aspx">Source</a> d&eacute;finie avec un fichier image. Un objet <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.ellipsegeometry%28v=VS.95%29.aspx">EllipseGeometry</a> avec une valeur <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.ellipsegeometry.radiusx%28v=VS.95%29.aspx">RadiusX</a> de 125, une valeur <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.ellipsegeometry.radiusy%28v=VS.95%29.aspx">RadiusY</a> de 100, et une valeur <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.ellipsegeometry.center%28v=VS.95%29.aspx">Center</a> de 225,175 est d&eacute;finie pour la propri&eacute;t&eacute; <a href="http://msdn.microsoft.com/en-us/library/system.windows.uielement.clip%28v=VS.95%29.aspx">Clip</a> de l&rsquo;<a href="http://go.microsoft.com/fwlink/?LinkId=129800">Image</a>. Seule la partie de l&rsquo;image qui est dans la zone de l&rsquo;ellipse sera affich&eacute;e.</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e0304d6b-0de0-4e10-9b8c-1fda1005eb96" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">XAML</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">Image</span><span style="color: #ff0000;"> Source</span><span style="color: #0000ff;">="Licorice.JPG"&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">Image.Clip</span><span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">EllipseGeometry</span><span style="color: #ff0000;"> RadiusX</span><span style="color: #0000ff;">="125"</span><span style="color: #ff0000;"> RadiusY</span><span style="color: #0000ff;">="100"</span><span style="color: #ff0000;"> Center</span><span style="color: #0000ff;">="225,175"/&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">Image.Clip</span><span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">Image</span><span style="color: #0000ff;">&gt;</span></li>
</ol></div>
</div>
</div>
<p>Voici le r&eacute;sultat dans l&rsquo;&eacute;mulateur.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/6445.image_thumb7_1F9229E9.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/6445.image_5F00_thumb7_5F00_1F9229E9.png"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image_thumb7" alt="image_thumb7" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/6471.image_thumb7_thumb_6B1157A0.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/6471.image_5F00_thumb7_5F00_thumb_5F00_6B1157A0.png" border="0" height="452" width="250" /></a></p>
<h2></h2>
<h2><a name="applying_an_opacitymask"></a>Appliquer un masque d&rsquo;opacit&eacute;</h2>
<p>Vous pouvez appliquer un <a href="http://go.microsoft.com/fwlink/?LinkId=129812">OpacityMask</a> sur une <a href="http://go.microsoft.com/fwlink/?LinkId=129800">Image</a> pour cr&eacute;er une vari&eacute;t&eacute; de techniques de masques d&rsquo;opacit&eacute; comme par exemple des effets de vignettage.</p>
<p>L&rsquo;exemple suivant montre comment appliquer un d&eacute;grad&eacute; radial sur une <a href="http://go.microsoft.com/fwlink/?LinkId=129800">Image</a> avec des fondus sur les bords (effet de vignette).</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:c6989585-22d1-4f40-9e30-41583d56c8d5" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">XAML</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">Image</span><span style="color: #ff0000;"> Source</span><span style="color: #0000ff;">="licorice.jpg" &gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">Image.OpacityMask</span><span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">RadialGradientBrush</span><span style="color: #ff0000;"> GradientOrigin</span><span style="color: #0000ff;">="0.5,0.5"</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">Center</span><span style="color: #0000ff;">="0.5,0.5"</span></li>
<li><span style="color: #ff0000;">RadiusX</span><span style="color: #0000ff;">="0.5"</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">RadiusY</span><span style="color: #0000ff;">="0.5"&gt;</span></li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #008000;">&lt;!-- These Gradient Stop colors are only changing the</span></li>
<li><span style="color: #008000;">alpha values so the image fades out toward the edges. --&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">GradientStop</span><span style="color: #ff0000;"> Color</span><span style="color: #0000ff;">="#ffffffff"</span><span style="color: #ff0000;"> Offset</span><span style="color: #0000ff;">="0.5" /&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">GradientStop</span><span style="color: #ff0000;"> Color</span><span style="color: #0000ff;">="#00ffffff"</span><span style="color: #ff0000;"> Offset</span><span style="color: #0000ff;">="0.8" /&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">RadialGradientBrush</span><span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">Image.OpacityMask</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">Image</span><span style="color: #0000ff;">&gt;</span></li>
</ol></div>
</div>
</div>
<p>Voici le r&eacute;sultat dans l&rsquo;&eacute;mulateur.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/8524.image_thumb9_3A9AD32A.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/8524.image_5F00_thumb9_5F00_3A9AD32A.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image_thumb9" alt="image_thumb9" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/1830.image_thumb9_thumb_65FEF424.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/1830.image_5F00_thumb9_5F00_thumb_5F00_65FEF424.png" border="0" height="417" width="231" /></a></p>
<h5>Remarque</h5>
<p>Vous pouvez utiliser une vari&eacute;t&eacute; d&rsquo;objets <b>Brush</b> pour un masque d&rsquo;opacit&eacute;. Pour plus d&rsquo;informations sur les pinceaux dans Silverlight pour Windows Phone, lisez l&rsquo;article <a href="http://create.msdn.com/en-US/education/quickstarts/brushes.aspx">Brushes QuickStart</a>.</p>
<p></p>
<h2></h2>
<h2><a name="creating_WriteableBitmaps"></a>Cr&eacute;er des WriteableBitmaps</h2>
<p>Un objet <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap%28VS.95%29.aspx">WriteableBitmap</a> fournit une <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapsource%28VS.95%29.aspx">BitmapSource</a> qui peut &ecirc;tre modifi&eacute;e. Cela vous permet de modifier les donn&eacute;es &agrave; la vol&eacute;e et de mettre &agrave; jour l'image.</p>
<p>Vous pouvez passer une <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapsource%28VS.95%29.aspx">BitmapSource</a>, les dimensions d'une nouvelle bitmap ou un <a href="http://msdn.microsoft.com/en-us/library/system.windows.uielement%28VS.95%29.aspx">UIElement</a> au constructeur du <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap%28VS.95%29.aspx">WriteableBitmap</a>. Passer un <a href="http://msdn.microsoft.com/en-us/library/system.windows.uielement%28VS.95%29.aspx">UIElement</a> va cr&eacute;er une image bitmap de l'&eacute;l&eacute;ment visuel. Par exemple, si vous voulez une image de tout l'arbre visuel, vous pouvez passer l'&eacute;l&eacute;ment <a href="http://msdn.microsoft.com/en-us/library/system.windows.uielement%28VS.95%29.aspx">UIElement</a> racine au constructeur.</p>
<p>La propri&eacute;t&eacute; <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.pixels%28v=VS.95%29.aspx">Pixels</a> du <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap%28VS.95%29.aspx">WriteableBitmap</a> est un tableau qui repr&eacute;sente la texture 2D du bitmap. Vous pouvez alt&eacute;rer l'image en modifiant les valeurs des pixels dans ce tableau.</p>
<h5>Remarque</h5>
<p>Le format utilis&eacute; par l'objet WriteableBitmap de Silverlight est ARGB32. Ainsi, les pixels dans le tableau de pixels d'un WriteableBitmap sont stock&eacute;s en tant que couleurs pr&eacute;-multipli&eacute;es. Chaque canal de couleur est pr&eacute;-multipli&eacute; par la valeur alpha.</p>
<h5>Remarque</h5>
<p>Les objets <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.mediaelement%28VS.95%29.aspx">MediaElement</a> n'apparaitront pas dans les captures WriteableBitmap. C'est parce que les <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.mediaelement%28VS.95%29.aspx">MediaElements</a> sont affich&eacute;s enti&egrave;rement de fa&ccedil;on hardware dans Silverlight pour Windows Phone.</p>
<p>L'exemple suivant montre comment cr&eacute;er une image <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap%28VS.95%29.aspx">WriteableBitmap</a> depuis un objet <a href="http://go.microsoft.com/fwlink/?LinkId=129800">Image</a> et comment modifier le <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap%28VS.95%29.aspx">WriteableBitmap</a>. Pour cr&eacute;er l'objet <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap%28VS.95%29.aspx">WriteableBitmap</a>, la propri&eacute;t&eacute; <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.image.source%28v=VS.95%29.aspx">Source</a> de l' <a href="http://go.microsoft.com/fwlink/?LinkId=129800">Image</a> est cast&eacute;e en <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapsource%28VS.95%29.aspx">BitmapSource</a> et est pass&eacute;e en param&egrave;tre au constructeur de <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap%28VS.95%29.aspx">WriteableBitmap</a>. Lorsque le bouton "Modify Pixels" est cliqu&eacute;, le gestionnaire d'&eacute;v&egrave;nement it&egrave;re sur le tableau de <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.pixels%28VS.95%29.aspx">Pixels</a> du bitmap et d&eacute;finit chacun d'entre eux sur noir. L'objet <a href="http://go.microsoft.com/fwlink/?LinkId=129800">Image</a> est alors modifi&eacute; par ce bitmap et est r&eacute;affich&eacute;.</p>
<p>Pour essayer cet exemple, cliquez sur <b>Modify Pixels</b> pour voir comment l'image est distordue.</p>
<h5>Remarque</h5>
<p>Cet exemple live utilise Silverlight pour simuler le comportement du Windows Phone. Le comportement peut n&eacute;anmoins &ecirc;tre l&eacute;g&egrave;rement diff&eacute;rent dans l'&eacute;mulateur Windows Phone ou d&rsquo;un vrai Windows Phone.</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:7f47d76e-6177-460e-a660-5ff40224e7a3" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">XAML</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">StackPanel</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">Image</span><span style="color: #ff0000;"> Name</span><span style="color: #0000ff;">="ImageToModify"</span><span style="color: #ff0000;"> Source</span><span style="color: #0000ff;">="licorice.jpg" /&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">StackPanel</span><span style="color: #ff0000;"> Orientation</span><span style="color: #0000ff;">="Horizontal"</span><span style="color: #ff0000;"> HorizontalAlignment</span><span style="color: #0000ff;">="Center"</span><span style="color: #ff0000;"> Margin</span><span style="color: #0000ff;">="30" &gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">Button</span><span style="color: #ff0000;"> Name</span><span style="color: #0000ff;">="ButtonModify"</span><span style="color: #ff0000;"> Content</span><span style="color: #0000ff;">="Modify Pixels"</span><span style="color: #ff0000;"> Click</span><span style="color: #0000ff;">="</span><span style="color: #ff0000;">ButtonModify_Click</span><span style="color: #0000ff;">" /&gt;</span></li>
<li><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">Button</span><span style="color: #ff0000;"> Name</span><span style="color: #0000ff;">="ButtonReset"</span><span style="color: #ff0000;"> Content</span><span style="color: #0000ff;">="Reset Image"</span><span style="color: #ff0000;"> Click</span><span style="color: #0000ff;">="</span><span style="color: #ff0000;">ButtonReset_Click</span><span style="color: #0000ff;">" /&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #a31515;"></span><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">StackPanel</span><span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">StackPanel</span><span style="color: #0000ff;">&gt;</span></li>
</ol></div>
</div>
</div>
<p></p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:938bc6d2-2c9c-4c33-b461-bf0512f060e3" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">C#</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> ButtonModify_Click(<span style="color: #0000ff;">object</span> sender, <span style="color: #ff0000;">RoutedEventArgs</span> e)</li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #0000ff;">int</span> pixelTarget = 4;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">if</span> (<span style="color: #ff0000;">ImageToModify</span>.Source != <span style="color: #0000ff;">null</span>)</li>
<li>{</li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// Get WriteableBitmap. ImageToModify is defined in MainPage.xaml</span></li>
<li><span style="color: #ff0000;">WriteableBitmap</span> bitmap =</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">new</span> <span style="color: #ff0000;">WriteableBitmap</span>(<span style="color: #ff0000;">ImageToModify</span>.Source <span style="color: #0000ff;">as</span> <span style="color: #ff0000;">BitmapSource</span>);</li>
<li><span style="color: #008000;">// Iterate through each pixel.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">for</span> (<span style="color: #0000ff;">int</span> x = 0; x &lt; bitmap.<span style="color: #ff0000;">Pixels</span>.Length; x++)</li>
<li>{</li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// Set every 4th pixel.</span></li>
<li><span style="color: #0000ff;">if</span> (x % pixelTarget == 0)</li>
<li style="background: #f3f3f3;">{</li>
<li>bitmap.<span style="color: #ff0000;">Pixels</span>[x] = 0;</li>
<li style="background: #f3f3f3;">}</li>
<li>}</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #008000;">// Set Image object, defined in XAML, to the modified bitmap.</span></li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">ImageToModify</span>.Source = bitmap;</li>
<li>}</li>
<li style="background: #f3f3f3;">}</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> ButtonReset_Click(<span style="color: #0000ff;">object</span> sender, <span style="color: #ff0000;">RoutedEventArgs</span> e)</li>
<li>{</li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">BitmapImage</span> licoriceImage =</li>
<li><span style="color: #0000ff;">new</span> <span style="color: #ff0000;">BitmapImage</span>(<span style="color: #0000ff;">new</span> <span style="color: #ff0000;">Uri</span>(<span style="color: #a31515;">"licorice.jpg"</span>, <span style="color: #ff0000;">UriKind</span>.Relative));</li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">ImageToModify</span>.Source = licoriceImage;</li>
<li>}</li>
</ol></div>
</div>
</div>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:a039328c-8a38-4ef4-829f-2b487a5d5ea4" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">Visual Basic</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">Private</span> <span style="color: #0000ff;">Sub</span> ButtonModify_Click(sender <span style="color: #0000ff;">As</span> <span style="color: #0000ff;">Object</span>, e <span style="color: #0000ff;">As</span> RoutedEventArgs)</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Dim</span> pixelTarget <span style="color: #0000ff;">As</span> <span style="color: #0000ff;">Integer</span> = 4</li>
<li><span style="color: #0000ff;">If</span> ImageToModify.Source <span style="color: #0000ff;">IsNot</span> <span style="color: #0000ff;">Nothing</span> <span style="color: #0000ff;">Then</span></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">' Get WriteableBitmap. ImageToModify is defined in MainPage.xaml</span></li>
<li><span style="color: #0000ff;">Dim</span> bitmap <span style="color: #0000ff;">As</span> <span style="color: #0000ff;">New</span> WriteableBitmap(<span style="color: #0000ff;">TryCast</span>(ImageToModify.Source, BitmapSource))</li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #008000;">' Iterate through each pixel.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">For</span> x <span style="color: #0000ff;">As</span> <span style="color: #0000ff;">Integer</span> = 0 <span style="color: #0000ff;">To</span> bitmap.Pixels.Length - 1</li>
<li><span style="color: #008000;">' Set every 4th pixel.</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">If</span> x <span style="color: #0000ff;">Mod</span> pixelTarget = 0 <span style="color: #0000ff;">Then</span></li>
<li>bitmap.Pixels(x) = 0</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">If</span></li>
<li><span style="color: #0000ff;">Next</span></li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #008000;">' Set Image object, defined in XAML, to the modified bitmap.</span></li>
<li style="background: #f3f3f3;">ImageToModify.Source = bitmap</li>
<li><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">If</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Sub</span></li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Private</span> <span style="color: #0000ff;">Sub</span> ButtonReset_Click(sender <span style="color: #0000ff;">As</span> <span style="color: #0000ff;">Object</span>, e <span style="color: #0000ff;">As</span> RoutedEventArgs)</li>
<li><span style="color: #0000ff;">Dim</span> licoriceImage <span style="color: #0000ff;">As</span> <span style="color: #0000ff;">New</span> BitmapImage(<span style="color: #0000ff;">New</span> <span style="color: #2b91af;">Uri</span>(<span style="color: #a31515;">"licorice.jpg"</span>, <span style="color: #2b91af;">UriKind</span>.Relative))</li>
<li style="background: #f3f3f3;">ImageToModify.Source = licoriceImage</li>
<li><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Sub</span></li>
</ol></div>
</div>
</div>
<p></p>
<h2>Voir aussi</h2>
<ul>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-17.aspx">Graphiques</a></li>
<li><a href="http://go.microsoft.com/fwlink/?LinkId=129813">Deep Zoom Overview</a> <a href="http://go.microsoft.com/fwlink/?LinkID=129653">Imaging</a></li>
</ul>
<hr />
<p><a href="#sommaire">Cliquez ici pour revenir au sommaire de la liste d&rsquo;articles</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Developpement Windows Phone - partie 11</title>
      <link>https://docs.microsoft.com/archive/blogs/lgmorand/developpement-windows-phone-partie-11</link>
      <pubDate>Tue, 06 Sep 2011 13:11:00 GMT</pubDate>
      <dc:creator><![CDATA[Louis-Guillaume Morand]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/lgmorand/2011/09/06/developpement-windows-phone-partie-11/</guid>
      <description><![CDATA[Ex&eacute;cuter votre application en arri&egrave;re-plan (Tombstoning)
Cet article fait partie...]]></description>
      <content:encoded><![CDATA[<h1>Ex&eacute;cuter votre application en arri&egrave;re-plan (Tombstoning)</h1>
<p>Cet article fait partie d&rsquo;une s&eacute;rie d&rsquo;articles sur le d&eacute;veloppement Windows Phone. Il s&rsquo;agit d&rsquo;une traduction des articles se trouvant <a href="http://create.msdn.com/en-us/education/quickstarts" target="_blank">sur la MSDN</a>.</p>
<h2><a name="sommaire"></a>Sommaire</h2>
<p><strong>Bien d&eacute;buter et fondamentaux</strong></p>
<ul>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-1.aspx" target="_blank">Bien d&eacute;marrer (Hello World)</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-2.aspx" target="_blank">Cr&eacute;er une interface utilisateur pour Windows Phone en XAML</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-3.aspx" target="_blank">Utiliser des contr&ocirc;les</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-4.aspx" target="_blank">Types de contr&ocirc;les</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-5.aspx" target="_blank">Contr&ocirc;les Panorama et Pivot</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-6.aspx" target="_blank">Travailler avec du texte sur le Windows Phone</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-7.aspx" target="_blank">Mise en page sur l&rsquo;&eacute;cran</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-8.aspx" target="_blank">Orientations de l&rsquo;&eacute;cran</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-9.aspx" target="_blank">Saisie tactile</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-10.aspx" target="_blank">Navigation</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-11.aspx" target="_blank">Ex&eacute;cuter votre application en arri&egrave;re-plan (tombstoning)</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-12.aspx" target="_blank">Notifications Push pour le d&eacute;veloppement Windows Phone</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-13.aspx" target="_blank">Publier votre application sur le Marketplace</a></li>
</ul>
<p><strong>Visuels et m&eacute;dia</strong></p>
<ul>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-14.aspx" target="_blank">Images</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-15.aspx" target="_blank">Animations</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-16.aspx" target="_blank">Vid&eacute;o et Audio</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-17.aspx" target="_blank">Graphiques</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-18.aspx" target="_blank">Pinceaux</a></li>
</ul>
<p><strong>Travailler avec les donn&eacute;es</strong></p>
<ul>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-19.aspx" target="_blank">Obtenir des donn&eacute;es dans vos applications Windows Phone</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-20.aspx" target="_blank">Data binding</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-21.aspx" target="_blank">Isolated storage</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-22.aspx" target="_blank">Acc&eacute;der &agrave; un service Web REST</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-23.aspx" target="_blank">Consommer des donn&eacute;es Windows Azure</a></li>
</ul>
<p><strong>Sondes et autres fonctionnalit&eacute;s sp&eacute;cifiques au t&eacute;l&eacute;phone</strong></p>
<ul>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-24.aspx" target="_blank">Lanceurs et choosers</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-25.aspx" target="_blank">D&eacute;tecter des mouvements (acc&eacute;l&eacute;rom&egrave;tres)</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-26.aspx" target="_blank">D&eacute;velopper avec le GPS Windows Phone (Services de localisation)</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-27.aspx" target="_blank">D&eacute;velopper avec l&rsquo;appareil photo du Windows Phone</a></li>
</ul>
<hr />
<h1>Data Binding</h1>
<p>La plupart des applications Windows Phone affichent des donn&eacute;es dans les contr&ocirc;les. Dans de nombreux cas, les donn&eacute;es sont des objets business tels que des actions en bourse, des titres de news ou des images. En plus, vous voulez souvent autoriser l'utilisateur &agrave; s&eacute;lectionner un &eacute;l&eacute;ment depuis une liste puis afficher les d&eacute;tails relatifs &agrave; cet &eacute;l&eacute;ment dans un autre contr&ocirc;le comme par exemple une zone de texte.</p>
<p>Ce tutoriel montre comment lier un contr&ocirc;le &agrave; un simple &eacute;l&eacute;ment et comment lier un contr&ocirc;le de liste &agrave; une collection d'&eacute;l&eacute;ments, De plus, vous verrez au sein de cet article comment personnaliser l'affichage des &eacute;l&eacute;ments, comment impl&eacute;menter une vue d&eacute;taill&eacute;e bas&eacute;e sur une s&eacute;lection et comment convertir les donn&eacute;es avant de les afficher.</p>
<p>Ce tutoriel contient les sections suivantes:</p>
<ul>
<li><a href="#BindingSingleItem">Lier un contr&ocirc;le &agrave; un &eacute;l&eacute;ment unique</a></li>
<li><a href="#BindingToCollection">Lier un contr&ocirc;le &agrave; une collection d'objets</a></li>
<li><a href="#DisplayingItemsWithDataTemplate">Afficher les &eacute;l&eacute;ments dans un contr&ocirc;le en utilisant un data template</a></li>
<li><a href="#AddingDetailsView">Ajouter une vue d&eacute;tails</a></li>
<li><a href="#ConvertingData">Convertir des donn&eacute;es pour les afficher dans des contr&ocirc;les</a></li>
</ul>
<p><strong>Sondes et autres fonctionnalit&eacute;s sp&eacute;cifiques au t&eacute;l&eacute;phone</strong></p>
<ul>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-24.aspx" target="_blank">Lanceurs et choosers</a></li>
<li><a href="http://blogs.msdn.com/b/jflavidalle/archive/2011/09/06/developpement-windows-phone-partie-25.aspx" target="_blank">D&eacute;tecter des mouvements (acc&eacute;l&eacute;rom&egrave;tres)</a></li>
<li><a href="http://blogs.msdn.com/b/lgmorand/archive/2011/09/06/developpement-windows-phone-partie-26.aspx" target="_blank">D&eacute;velopper avec le GPS Windows Phone (Services de localisation)</a></li>
<li><a href="http://blogs.msdn.com/b/patrick_payet/archive/2011/09/06/developpement-windows-phone-partie-27.aspx" target="_blank">D&eacute;velopper avec l&rsquo;appareil photo du Windows Phone</a></li>
</ul>
<hr />
<h1>Ex&eacute;cuter votre application en arri&egrave;re-plan (Tombstoning)</h1>
<p>Le syst&egrave;me d'exploitation de Windows Phone autorise une seule application &agrave; s'ex&eacute;cuter &agrave; la fois. Lorsque l'utilisateur quitte l'application, le syst&egrave;me arr&ecirc;te l'application. Pour offrir une exp&eacute;rience transparente &agrave; l'utilisateur, le syst&egrave;me fournit un support pour restaurer l'application dans un &eacute;tat pr&eacute;sentable lorsqu'elle est r&eacute;activ&eacute;e. Ce tutoriel d&eacute;crit le processus de d&eacute;sactivation, le cycle d'ex&eacute;cution de l'application, et comment restaurer un &eacute;tat.</p>
<p>Ce tutoriel contient les sections suivantes:</p>
<ul>
<li><a href="#Overview">Aper&ccedil;u de la d&eacute;sactivation</a></li>
<li><a href="#ApplicationLifecycle">Cycle de vie de l'application</a></li>
<li><a href="#ApplicationState">Etat d'application</a></li>
<li><a href="#PageState">Etat de page</a></li>
<li><a href="#BestPractices">Bonnes pratiques</a></li>
</ul>
<h2></h2>
<h2><a name="Overview"></a>Aper&ccedil;u de la d&eacute;sactivation</h2>
<p>Le syst&egrave;me d'exploitation n'autorise pas d'application-tiers &agrave; s'ex&eacute;cuter en arri&egrave;re-plan; c'est pourquoi, seulement une application peut fonctionner &agrave; la fois. Les raisons pour ne pas autoriser d'autres applications &agrave; fonctionner en arri&egrave;re-plan sont de pr&eacute;server la batterie du t&eacute;l&eacute;phone et d'assurer une r&eacute;activit&eacute; rapide de l'interface.</p>
<p>Lorsque l'utilisateur quitte l'application, le syst&egrave;me d&eacute;sactive l'application. Cette d&eacute;sactivation/hibernation est appel&eacute;e le <i>tombstoning</i>. C'est le processus dans lequel le syst&egrave;me d'exploitation d&eacute;sactive le process de l'application. Une application peut &ecirc;tre d&eacute;sactiv&eacute;e dans les cas suivants:</p>
<ul>
<li>Un coup de fil est re&ccedil;u. La r&eacute;activation s'ex&eacute;cute lorsque l'appel s'arr&ecirc;te.</li>
<li>Le t&eacute;l&eacute;phone se met en veille. La r&eacute;activation s'ex&eacute;cute lorsque l'utilisateur relance le t&eacute;l&eacute;phone.</li>
<li>L'utilisateur appuie sur le bouton D&eacute;marrer ou le bouton Recherche, ou r&eacute;pond &agrave; une notification. La r&eacute;activation s'ex&eacute;cute lorsque l'utilisateur revient &agrave; l'application en cliquant une ou plusieurs fois sur le bouton Retour.</li>
<li>L'application invoque une t&acirc;che externe. La r&eacute;activation s'ex&eacute;cute lorsque l'utilisateur a compl&eacute;t&eacute; la t&acirc;che.</li>
</ul>
<p>Lorsque l'application d&eacute;sactiv&eacute;e est r&eacute;activ&eacute;e, elle doit afficher le m&ecirc;me &eacute;tat que juste avant sa d&eacute;sactivation pour fournir une exp&eacute;rience transparente &agrave; l'utilisateur. Id&eacute;alement, l'utilisateur ne devrait pas savoir qu'il s'agit d'un nouveau process lorsqu'il r&eacute;active l'application. Par exemple, supposez que vous ouvrez une application avec une grande page et que vous avez un peu d&eacute;fil&eacute; la page pour lire le texte, avant de passer &agrave; une autre page. Lorsque vous revenez sur la premi&egrave;re page, ce n'est pas trop g&ecirc;nant si vous avez perdu votre position et &ecirc;tes revenu en haut de la page. Par contre, si vous venez de passer plusieurs minutes &agrave; remplir un formulaire, vous n'avez pas envie de perdre toute votre saisie si une autre page vous dit que vous avez fait une petite erreur.</p>
<p>Pour achever cela, lorsque l'application est d&eacute;sactiv&eacute;e, le syst&egrave;me maintien des informations &agrave; propos de l'application en m&eacute;moire et utilise ces informations pour restaurer votre application dans un &eacute;tat pr&eacute;sentable lorsque celle-ci est r&eacute;activ&eacute;e.</p>
<p>Windows Phone fournit des m&eacute;thodes et &eacute;v&egrave;nements pour enregistrer et restaurer les &eacute;tats des applications et des pages. Ces m&eacute;thodes et &eacute;v&egrave;nements seront d&eacute;crits plus loin dans cet article.</p>
<h2><a name="ApplicationLifecycl"></a>Cycle de vie de l'application</h2>
<p>Depuis que les applications Windows Phone peuvent &ecirc;tre hibern&eacute;es, elles ont un cycle vie unique que vous devez comprendre. Le syst&egrave;me d'exploitation fournit quatre &eacute;v&egrave;nements qui indiquent l'&eacute;tat de votre application dans son cycle de vie. Vous pouvez utiliser ces &eacute;v&egrave;nements pour effectuer des actions appropri&eacute;es dans votre application. Ces &eacute;v&egrave;nements sont <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.phoneapplicationservice.launching%28VS.92%29.aspx">Launching</a>, <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.phoneapplicationservice.closing%28VS.92%29.aspx">Closing</a>, <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.phoneapplicationservice.deactivated%28VS.92%29.aspx">Deactivated</a>, et <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.phoneapplicationservice.activated%28VS.92%29.aspx">Activated</a>. L'illustration suivante montre &agrave; quels moments ils sont d&eacute;clench&eacute;s.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/5287.image_thumb5_4AF34CE9.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/5287.image_5F00_thumb5_5F00_4AF34CE9.png"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image_thumb5" alt="image_thumb5" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/8836.image_thumb5_thumb_337898B8.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/8836.image_5F00_thumb5_5F00_thumb_5F00_337898B8.png" border="0" height="502" width="365" /></a></p>
<p><b>Lancement</b></p>
<p>Lorsqu'une application est ex&eacute;cut&eacute;e depuis l'&eacute;cran de d&eacute;marrage, on dit qu'elle est <i>lanc&eacute;e</i> (<i>launched</i>). Lorsqu'un utilisateur lance une application, une nouvelle instance de l'application est cr&eacute;&eacute;e. Lorsque l'application est d&eacute;marr&eacute;e un &eacute;v&egrave;nement <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.phoneapplicationservice.launching%28VS.92%29.aspx">Launching</a> est d&eacute;clench&eacute;. Le code qui suit montre l'&eacute;v&egrave;nement <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.phoneapplicationservice.launching%28VS.92%29.aspx">Launching</a> qui est pr&eacute;sent dans le fichier App.xaml.cs.</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:609cc35b-771c-419b-a3e5-b53a56e20edc" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">C#</div>
<div style="background: #ddd; max-height: 500px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #008000;">// Code to execute when the application is launching (eg, from Start)</span></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// This code will not execute when the application is reactivated</span></li>
<li><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> Application_Launching(<span style="color: #0000ff;">object</span> sender, <span style="color: #ff0000;">LaunchingEventArgs</span> e)</li>
<li style="background: #f3f3f3;">{</li>
<li></li>
<li style="background: #f3f3f3;">}</li>
</ol></div>
</div>
</div>
<p>Vous pouvez utiliser l'&eacute;v&egrave;nement <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.phoneapplicationservice.launching%28VS.92%29.aspx">Launching</a> pour sauvegarder de fa&ccedil;on incr&eacute;mentale la configuration et persist&eacute;es les donn&eacute;es pour r&eacute;duire le nombre de donn&eacute;es qui ont besoins d'&ecirc;tre sauvegard&eacute;es lorsque l'&eacute;tat de l'application change. C'est optionnel pour les applications avec peu de donn&eacute;es &agrave; persister.</p>
<p><b>Closing</b></p>
<p>En appuyant sur le bouton Retour du t&eacute;l&eacute;phone, le mod&egrave;le de navigation permet aux utilisateurs de "revenir en arri&egrave;re", ou de naviguer en arri&egrave;re &agrave; travers les diff&eacute;rentes pages de l'application, et m&ecirc;me &agrave; travers plusieurs applications. Pourtant, une fois que l'utilisateur atteint la premi&egrave;re page d'une application, l'appui sur le bouton Retour d&eacute;clenche l'&eacute;v&egrave;nement <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.phoneapplicationservice.closing%28VS.92%29.aspx">Closing</a> et termine votre application. Vous pouvez utiliser cet &eacute;v&egrave;nement pour enregistrer les donn&eacute;es persistantes dans l'Isolated Storage. Le code suivant montre l'&eacute;v&egrave;nement <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.phoneapplicationservice.closing%28VS.92%29.aspx">Closing</a> pr&eacute;sent dans le fichier App.xaml.cs.</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:0142a946-2b84-4b71-a355-e1196555c8df" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">C#</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #008000;">// Code to execute when the application is closing (eg, user hit Back)</span></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// This code will not execute when the application is deactivated</span></li>
<li><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> Application_Closing(<span style="color: #0000ff;">object</span> sender, <span style="color: #ff0000;">ClosingEventArgs</span> e)</li>
<li style="background: #f3f3f3;">{</li>
<li></li>
<li style="background: #f3f3f3;">}</li>
</ol></div>
</div>
</div>
<p><b>Deativated</b></p>
<p>Une application pourrait &ecirc;tre d&eacute;sactiv&eacute;e (non ferm&eacute;e) soit &agrave; la suite d&rsquo;une autre application prenant le contr&ocirc;le du premier plan, comme un appel entrant, soit &agrave; la suite de l'appui du bouton D&eacute;marrer par l'utilisateur. Dans ces cas-l&agrave;, l'&eacute;v&egrave;nement <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.phoneapplicationservice.deactivated%28VS.92%29.aspx">Deactivated</a> est d&eacute;clench&eacute;. Le code suivant est un exemple de l'&eacute;v&egrave;nement <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.phoneapplicationservice.deactivated%28VS.92%29.aspx">Deactivated</a> dans le fichier App.xaml.cs.</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:8e3e2819-c1bd-40e9-9f07-d20f6b2ab2c4" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">C#</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #008000;">// Code to execute when the application is deactivated (sent to background)</span></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// This code will not execute when the application is closing</span></li>
<li><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> Application_Deactivated(<span style="color: #0000ff;">object</span> sender, <span style="color: #ff0000;">DeactivatedEventArgs</span> e)</li>
<li style="background: #f3f3f3;">{</li>
<li></li>
<li style="background: #f3f3f3;">}</li>
</ol></div>
</div>
</div>
<p>Contrairement &agrave; une application qui est ferm&eacute;e (activ&eacute;e), une application d&eacute;sactiv&eacute;e peut &ecirc;tre hibern&eacute;e. Cela signifie qu'elle n'est plus en cours d'ex&eacute;cution mais que le syst&egrave;me garde une trace de l'application et stocke des donn&eacute;es sur l'&eacute;tat de cette application. Il est possible que l'utilisateur retourne sur une application hibern&eacute;e. Ainsi, vous devriez enregistrer les informations d'&eacute;tat de votre application en utilisant le dictionnaire expos&eacute; &agrave; travers la propri&eacute;t&eacute; <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.phoneapplicationservice.state%28VS.92%29.aspx">PhoneApplicationService.State</a> dans le gestionnaire d'&eacute;v&egrave;nement <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.phoneapplicationservice.deactivated%28VS.92%29.aspx">Deactivated</a>. Les donn&eacute;es enregistr&eacute;es dans ce dictionnaire sont des donn&eacute;es d'&eacute;tat transitoire, c'est-&agrave;-dire des donn&eacute;es qui vous aident &agrave; r&eacute;tablir l'&eacute;tat de l'application avant qu'elle ne soit d&eacute;sactiv&eacute;e. Parce qu'il n'y aucune garantie qu'une application hibern&eacute;e soit un jour relanc&eacute;e, vous devriez aussi enregistrer une partie de cet &eacute;tat dans l'Isolated Storage par la m&ecirc;me occasion. Toutes les actions effectu&eacute;es dans le gestionnaire d'&eacute;v&eacute;nement <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.phoneapplicationservice.deactivated%28VS.92%29.aspx">Deactivated</a> doivent &ecirc;tre r&eacute;alis&eacute;es en moins de 10 secondes ou le syst&egrave;me pourrait couper brutalement l'application. Ainsi, si votre application a beaucoup de donn&eacute;es &agrave; sauvegarder, tentez de les enregistrer de fa&ccedil;on incr&eacute;mentielle.</p>
<p>Il est aussi possible pour une application d'&ecirc;tre d&eacute;sactiv&eacute;e sans &ecirc;tre hibern&eacute;e. Par exemple, si l'utilisateur clique sur le bouton D&eacute;marrer puis sur le bouton Retour dans un laps de temps tr&egrave;s court. Pour cette raison, il est important de ne rien faire de destructif dans le gestionnaire d'&eacute;v&egrave;nement <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.phoneapplicationservice.deactivated%28VS.92%29.aspx">Deactivated</a>. Votre application devrait &ecirc;tre capable de continuer apr&egrave;s avoir compl&eacute;t&eacute; l'&eacute;v&egrave;nement <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.phoneapplicationservice.deactivated%28VS.92%29.aspx">Deactivated</a> sans que l'&eacute;v&egrave;nement <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.phoneapplicationservice.activated%28VS.92%29.aspx">Activated</a> ne soit appel&eacute;.</p>
<p></p>
<p><b>Activated</b></p>
<p>Apr&egrave;s qu'une application ait &eacute;t&eacute; d&eacute;sactiv&eacute;e et mise en hibernation, l'utilisateur peut retourner &agrave; l'application en cliquant sur le bouton Retour jusqu'&agrave; retourner sur l&rsquo;application. Lorsque l&rsquo;utilisateur retourne sur une application hibern&eacute;e, celle-ci est r&eacute;activ&eacute;e et l&rsquo;&eacute;v&egrave;nement <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.phoneapplicationservice.activated%28VS.92%29.aspx">Activated</a> est d&eacute;clench&eacute;. Vous pouvez utiliser cet &eacute;v&egrave;nement pour lire les valeurs depuis <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.phoneapplicationservice.state%28VS.92%29.aspx">PhoneApplicationService.State</a> pour r&eacute;cup&eacute;rer l&rsquo;&eacute;tat de l&rsquo;application tel que l&rsquo;utilisateur l&rsquo;avait laiss&eacute;. Le code suivant montre l'&eacute;v&egrave;nement <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.phoneapplicationservice.activated%28VS.92%29.aspx">Activated</a> dans le fichier App.xaml.cs</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:5a52dabe-69e6-4a88-b2bc-d4d64e6ebcb8" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">C#</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #008000;">// Code to execute when the application is activated (brought to foreground)</span></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">// This code will not execute when the application is first launched</span></li>
<li><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> Application_Activated(<span style="color: #0000ff;">object</span> sender, <span style="color: #ff0000;">ActivatedEventArgs</span> e)</li>
<li style="background: #f3f3f3;">{</li>
<li></li>
<li style="background: #f3f3f3;">}</li>
</ol></div>
</div>
</div>
<h2></h2>
<h2><a name="ApplicationState"></a>Etat d'application</h2>
<p><i>Application state</i> est l'&eacute;tat de l'application qui n'est sp&eacute;cifique &agrave; aucune page particuli&egrave;re. Si votre application utilise des donn&eacute;es globales comme des informations de login ou la configuration de l'application comme les th&egrave;mes, il est probable qu'ils seront utilis&eacute;s par plusieurs pages de votre application. Ces donn&eacute;es sont consid&eacute;r&eacute;es comme partie de l'&eacute;tat de l'application. Lorsque votre application est r&eacute;activ&eacute;e apr&egrave;s avoir &eacute;t&eacute; hibern&eacute;e, les donn&eacute;es sont perdues &agrave; moins que vous sauvegardiez sp&eacute;cifiquement les donn&eacute;es. En g&eacute;n&eacute;ral vous utilisez les &eacute;v&egrave;nements <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.phoneapplicationservice.launching%28VS.92%29.aspx">Launching</a>, <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.phoneapplicationservice.closing%28VS.92%29.aspx">Closing</a>, <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.phoneapplicationservice.deactivated%28VS.92%29.aspx">Deactivated</a> et <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.phoneapplicationservice.activated%28VS.92%29.aspx">Activated</a> pour initialiser et maintenir un &eacute;tat d'application. Lorsque votre application est m&eacute;moris&eacute;e, le syst&egrave;me d'exploitation sauvegarde le contenu du dictionnaire qui est expos&eacute; par la propri&eacute;t&eacute; <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.phoneapplicationservice.state%28VS.92%29.aspx">PhoneApplicationService.State</a>. Vous pouvez enregistrer l'&eacute;tat de votre application lors de l'&eacute;v&egrave;nement <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.phoneapplicationservice.deactivated%28VS.92%29.aspx">Deactivated</a> et le r&eacute;cup&eacute;rer lors de l'&eacute;v&egrave;nement <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.phoneapplicationservice.state%28VS.92%29.aspx">PhoneApplicationService.State</a>. Plus d'informations sont disponibles dans l'article <a href="http://msdn.microsoft.com/en-us/library/ff967547%28VS.92%29.aspx">How to: Preserve and Restore Application State for Windows Phone</a>.</p>
<p>Si votre application a des donn&eacute;es persistantes, vous pouvez stocker ces donn&eacute;es dans l'Isolated Storage plut&ocirc;t que d&rsquo;utiliser un dictionnaire d'&eacute;tat. L'Isolated Storage est un espace de stockage bac &agrave; sable sur le disque de votre t&eacute;l&eacute;phone. Il est analogue au syst&egrave;me de fichier de votre ordinateur de bureau. Les donn&eacute;es enregistr&eacute;es dans l'Isolated Storage peuvent prendre plusieurs secondes &agrave; charger et vous devez donc utiliser cela uniquement pour les donn&eacute;es qui requi&egrave;rent un stockage dans la dur&eacute;e et pour les objets non s&eacute;rialisables. De plus, vous devriez consid&eacute;rer avec attention o&ugrave; vous placez votre code pour l'Isolated Storage afin de minimiser l'impact sur des latences possibles dans votre application. Par exemple, si vous avez beaucoup de donn&eacute;es &agrave; enregistrer, vous devriez &eacute;viter de toutes les sauvegarder d'un coup. En g&eacute;n&eacute;ral, vous devriez sauvegarder les donn&eacute;es dans l'Isolated Storage d&egrave;s qu'il devient accessible ou d&egrave;s que possible. Pour plus d'informations, lisez le tutoriel sur l'Isolated Storage.</p>
<h2><a name="PageState"></a>Etat de page</h2>
<p>L'&eacute;tat de page est l'&eacute;tat visuel d'une page de votre application. Lorsque l'utilisateur clique sur le bouton Retour pour revenir &agrave; une application hibern&eacute;e, le syst&egrave;me d'exploitation Windows Phone va automatiquement afficher la derni&egrave;re page que l'utilisateur a visualis&eacute;. Pourtant, vous &ecirc;tes responsable d&rsquo;assurer que l'&eacute;tat de la page est sauvegard&eacute; et restaur&eacute; pour qu'elle ressemble &agrave; ce qu'elle &eacute;tait lorsque l'utilisateur l'a quitt&eacute;. L'&eacute;tat de page inclut diff&eacute;rentes choses telles que le contenu d'une zone de texte et la position de d&eacute;filement d'un scrollviewer. Cette section vous montrera comment vous pouvez enregistrer et restaurer l'&eacute;tat visuel d'une page pour fournir une exp&eacute;rience transparente &agrave; l'utilisateur.</p>
<p>Pour enregistrer et restaurer l'&eacute;tat visuel d'une page, vous devez utiliser le constructeur, la m&eacute;thode <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.controls.phoneapplicationpage.onnavigatedto%28VS.92%29.aspx">OnNavigatedTo</a> et la m&eacute;thode <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.page.onnavigatingfrom%28VS.92%29.aspx">OnNavigatedFrom</a>. Le constructeur de page est appel&eacute; lors de la premi&egrave;re navigation sur cette page. <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.controls.phoneapplicationpage.onnavigatedto%28VS.92%29.aspx">OnNavigatedTo</a> est appel&eacute;e &agrave; chaque fois que l'utilisateur arrive sur la page et que la page est disponible pour utilisation. <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.page.onnavigatingfrom%28VS.92%29.aspx">OnNavigatedFrom</a> est appel&eacute;e chaque fois que l'utilisateur quitte la page mais avant que la page ait commenc&eacute; &agrave; &ecirc;tre d&eacute;charg&eacute;e.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/8814.image_thumb3_45E0E96D.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/8814.image_5F00_thumb3_5F00_45E0E96D.png"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image_thumb3" alt="image_thumb3" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/2553.image_thumb3_thumb_4357B7AF.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/2553.image_5F00_thumb3_5F00_thumb_5F00_4357B7AF.png" border="0" height="376" width="539" /></a></p>
<p>Pour sauvegarder et restaurer l'&eacute;tat d'une page, vous devez effectuer normalement les &eacute;tapes suivantes.</p>
<ul>
<li>Ajoutez un membre bool&eacute;en dans la page (nomm&eacute; <b>newPageInstance</b> dans le code de l&rsquo;exemple qui suit) et mettez-lui la valeur <i>false</i>. Cette variable sera utilis&eacute;e pour d&eacute;terminer si l'UI a besoin d'&ecirc;tre restaur&eacute;e.</li>
<li>Dans le constructeur de la page, mettez la variable de page &agrave; <i>true</i>. Ce constructeur sera appel&eacute; lorsque la page est cr&eacute;&eacute;e pour la premi&egrave;re fois ou si la page est recr&eacute;&eacute;e apr&egrave;s que l'application ait hibern&eacute;. Le constructeur ne sera pas appel&eacute; si l'utilisateur revient d'une autre page vers celle-l&agrave; parce que la page est d&eacute;j&agrave; en m&eacute;moire.</li>
<li>Surchargez et impl&eacute;mentez la m&eacute;thode <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.controls.phoneapplicationpage.onnavigatedto%28VS.92%29.aspx">OnNavigatedTo</a>. Dans cette m&eacute;thode, r&eacute;cup&eacute;rez les donn&eacute;es d'&eacute;tat de la page depuis la propri&eacute;t&eacute; <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.controls.phoneapplicationpage.state%28VS.92%29.aspx">PhoneApplicationPage.State</a>.</li>
<li>Surchargez et impl&eacute;mentez la m&eacute;thode <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.page.onnavigatingfrom%28VS.92%29.aspx">OnNavigatedFrom</a>. Dans cette m&eacute;thode, enregistrez l'&eacute;tat de la page dans la propri&eacute;t&eacute; <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.controls.phoneapplicationpage.state%28VS.92%29.aspx">PhoneApplicationPage.State</a> .</li>
</ul>
<p>L'exemple suivant a deux pages nomm&eacute;es home page et seconde page. Lorsque vous cliquez sur le bouton <b>Go to the Second Page</b> de la page d'accueil, l'application navigue jusqu'&agrave; la seconde page. La seconde page poss&egrave;de un formulaire avec une zone de texte, deux boutons radio et une case &agrave; cocher. Si vous entrez des donn&eacute;es dans le formulaire et appuyez sur le bouton D&eacute;marrer pour quitter l'application, l'application hibernera. Si vous revenez au formulaire en cliquant sur le bouton Retour, vous pouvez voir que les donn&eacute;es saisies avant de quitter l'application sont restaur&eacute;es.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/4617.image_thumb1_40CE85F1.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/4617.image_5F00_thumb1_5F00_40CE85F1.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image_thumb1" alt="image_thumb1" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/39/51/metablogapi/1376.image_thumb1_thumb_36B9E4C6.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-51-metablogapi/1376.image_5F00_thumb1_5F00_thumb_5F00_36B9E4C6.png" border="0" height="265" width="650" /></a></p>
<p>L'illustration suivante montre le comportement si vous n'incluez pas le code pour restaurer l'&eacute;tat de la page.</p>
<p>Ajoutez le code suivant dans la seconde page et restaurez l'&eacute;tat de la page.</p>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:afdf8c84-443a-4b62-93d9-ee5d090365af" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">C#</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">public</span> <span style="color: #ff0000;">partial</span> <span style="color: #0000ff;">class</span> <span style="color: #2b91af;">SecondPage</span> : <span style="color: #2b91af;">PhoneApplicationPage</span></li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #0000ff;">bool</span> newPageInstance = <span style="color: #0000ff;">false</span>;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">public</span> <span style="color: #ff0000;">SecondPage</span>()</li>
<li>{</li>
<li style="background: #f3f3f3;">InitializeComponent();</li>
<li>newPageInstance = <span style="color: #0000ff;">true</span>;</li>
<li style="background: #f3f3f3;">}</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span> OnNavigatedTo(System.Windows.Navigation.<span style="color: #2b91af;">NavigationEventArgs</span> <span style="color: #ff0000;">e</span>)</li>
<li>{</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">if</span> (State.ContainsKey(<span style="color: #a31515;">"textbox"</span>) &amp;&amp; newPageInstance == <span style="color: #0000ff;">true</span>)</li>
<li>{</li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">MyTB</span>.Text = (<span style="color: #0000ff;">string</span>)State[<span style="color: #a31515;">"textbox"</span>];</li>
<li><span style="color: #ff0000;">MyRB1</span>.IsChecked = (<span style="color: #0000ff;">bool</span>?)State[<span style="color: #a31515;">"radiobutton1"</span>];</li>
<li style="background: #f3f3f3;"><span style="color: #ff0000;">MyRB2</span>.IsChecked = (<span style="color: #0000ff;">bool</span>?)State[<span style="color: #a31515;">"radiobutton2"</span>];</li>
<li><span style="color: #ff0000;">MyCB</span>.IsChecked = (<span style="color: #0000ff;">bool</span>?)State[<span style="color: #a31515;">"checkbox"</span>];</li>
<li style="background: #f3f3f3;">}</li>
<li><span style="color: #0000ff;">base</span>.OnNavigatedTo(<span style="color: #ff0000;">e</span>);</li>
<li style="background: #f3f3f3;">}</li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span> OnNavigatedFrom(System.Windows.Navigation.<span style="color: #2b91af;">NavigationEventArgs</span> <span style="color: #ff0000;">e</span>)</li>
<li>{</li>
<li style="background: #f3f3f3;">newPageInstance = <span style="color: #0000ff;">false</span>;</li>
<li>State[<span style="color: #a31515;">"textbox"</span>] = <span style="color: #ff0000;">MyTB</span>.Text;</li>
<li style="background: #f3f3f3;">State[<span style="color: #a31515;">"radiobutton1"</span>] = <span style="color: #ff0000;">MyRB1</span>.IsChecked;</li>
<li>State[<span style="color: #a31515;">"radiobutton2"</span>] = <span style="color: #ff0000;">MyRB2</span>.IsChecked;</li>
<li style="background: #f3f3f3;">State[<span style="color: #a31515;">"checkbox"</span>] = <span style="color: #ff0000;">MyCB</span>.IsChecked;</li>
<li><span style="color: #0000ff;">base</span>.OnNavigatedFrom(<span style="color: #ff0000;">e</span>);</li>
<li style="background: #f3f3f3;">}</li>
<li>}</li>
</ol></div>
</div>
</div>
<div style="margin: 0px; display: inline; float: none; padding: 0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:af581d29-5e7f-44d7-bcca-52c140d7f17d" class="class">
<div style="font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border: #000080 1px solid;">
<div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px;">Visual Basic</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px;">
<li><span style="color: #0000ff;">Partial</span> <span style="color: #0000ff;">Public</span> <span style="color: #0000ff;">Class</span> <span style="color: #2b91af;">SecondPage</span></li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #0000ff;">Inherits</span> <span style="color: #ff0000;">PhoneApplicationPage</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Private</span> newPageInstance <span style="color: #0000ff;">As</span> <span style="color: #0000ff;">Boolean</span> = <span style="color: #0000ff;">False</span></li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Public</span> <span style="color: #0000ff;">Sub</span> <span style="color: #0000ff;">New</span>()</li>
<li>InitializeComponent()</li>
<li style="background: #f3f3f3;">newPageInstance = <span style="color: #0000ff;">True</span></li>
<li><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Sub</span></li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #0000ff;">Protected</span> <span style="color: #0000ff;">Overrides</span> <span style="color: #0000ff;">Sub</span> OnNavigatedTo(e <span style="color: #0000ff;">As</span> System.Windows.Navigation.NavigationEventArgs)</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">If</span> State.ContainsKey(<span style="color: #a31515;">"textbox"</span>) <span style="color: #0000ff;">AndAlso</span> newPageInstance = <span style="color: #0000ff;">True</span> <span style="color: #0000ff;">Then</span></li>
<li>MyTB.Text = <span style="color: #0000ff;">DirectCast</span>(State(<span style="color: #a31515;">"textbox"</span>), <span style="color: #0000ff;">String</span>)</li>
<li style="background: #f3f3f3;">MyRB1.IsChecked = <span style="color: #0000ff;">CType</span>(State(<span style="color: #a31515;">"radiobutton1"</span>), System.<span style="color: #2b91af;">Nullable</span>(<span style="color: #0000ff;">Of</span> <span style="color: #0000ff;">Boolean</span>))</li>
<li>MyRB2.IsChecked = <span style="color: #0000ff;">CType</span>(State(<span style="color: #a31515;">"radiobutton2"</span>), System.<span style="color: #2b91af;">Nullable</span>(<span style="color: #0000ff;">Of</span> <span style="color: #0000ff;">Boolean</span>))</li>
<li style="background: #f3f3f3;">MyCB.IsChecked = <span style="color: #0000ff;">CType</span>(State(<span style="color: #a31515;">"checkbox"</span>), System.<span style="color: #2b91af;">Nullable</span>(<span style="color: #0000ff;">Of</span> <span style="color: #0000ff;">Boolean</span>))</li>
<li><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">If</span></li>
<li style="background: #f3f3f3;"></li>
<li><span style="color: #0000ff;">MyBase</span>.OnNavigatedTo(e)</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Sub</span></li>
<li></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">Protected</span> <span style="color: #0000ff;">Overrides</span> <span style="color: #0000ff;">Sub</span> OnNavigatedFrom(e <span style="color: #0000ff;">As</span> System.Windows.Navigation.NavigationEventArgs)</li>
<li>newPageInstance = <span style="color: #0000ff;">False</span></li>
<li style="background: #f3f3f3;">State(<span style="color: #a31515;">"textbox"</span>) = MyTB.Text</li>
<li>State(<span style="color: #a31515;">"radiobutton1"</span>) = MyRB1.IsChecked</li>
<li style="background: #f3f3f3;">State(<span style="color: #a31515;">"radiobutton2"</span>) = MyRB2.IsChecked</li>
<li>State(<span style="color: #a31515;">"checkbox"</span>) = MyCB.IsChecked</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">MyBase</span>.OnNavigatedFrom(e)</li>
<li><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Sub</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">End</span> <span style="color: #0000ff;">Class</span></li>
</ol></div>
</div>
</div>
<p>Pour plus d'informations sur l'&eacute;tat de page, lisez <a href="http://msdn.microsoft.com/en-us/library/ff967548%28VS.92%29.aspx">How to: Preserve and Restore Page State for Windows Phone</a>.</p>
<h2></h2>
<h2><a name="BestPractices"></a>Bonnes pratiques</h2>
<p>Voici quelques bonnes pratiques que vous pouvez suivre lors de votre d&eacute;veloppement d'applications Windows Phone:</p>
<ul>
<li>Lorsque votre application est lanc&eacute;e, depuis une tuile ou depuis la liste des applications install&eacute;es, l'utilisateur doit acc&eacute;der &agrave; la racine (home) de votre application. Il doit &ecirc;tre clair pour l'utilisateur qu'ils utilisent une nouvelle instance de votre application.</li>
<li>Lorsque votre application est activ&eacute;e depuis un &eacute;tat hibern&eacute;, l'utilisateur doit avoir l'impression que l'application est exactement identique au moment o&ugrave; celle-ci a &eacute;t&eacute; d&eacute;sactiv&eacute;e. Cela doit &ecirc;tre transparent pour l'utilisateur que l'application ait &eacute;t&eacute; arr&ecirc;t&eacute;e puis red&eacute;marr&eacute;e.</li>
<li>Apr&egrave;s que l'application soit hibern&eacute;e, l'utilisateur peut ne pas revenir &agrave; l'application imm&eacute;diatement. Pour cette raison, vous devriez sauvegarder un &eacute;tat persistant &agrave; la fois dans l'&eacute;v&egrave;nement <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.phoneapplicationservice.deactivated%28VS.92%29.aspx">Deactivated</a> et dans l'&eacute;v&egrave;nement <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.phoneapplicationservice.closing%28VS.92%29.aspx">Closing</a>. Pour &eacute;viter de dupliquer le code, vous pourriez vouloir cr&eacute;er une seule m&eacute;thode en charge de la sauvegarde de l'&eacute;tat et d'appeler cette m&eacute;thode depuis les deux gestionnaires d'&eacute;v&egrave;nement.</li>
<li>L&rsquo;application doit compl&eacute;ter toutes les actions dans le gestionnaire d'&eacute;v&egrave;nement <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.phoneapplicationservice.Deactivated%28VS.92%29.aspx">Deactivated</a> en moins de 10 secondes. Si l'application prend plus de 10 secondes pour hiberner alors le syst&egrave;me la coupera brutalement et l'application ne sera plus accessible via le bouton Retour. Il est donc recommand&eacute; que vous visiez un temps d'hibernation le plus court possible. Si vous avez beaucoup de donn&eacute;es &agrave; sauvegarder, vous pouvez le faire de fa&ccedil;on incr&eacute;mentale dans l'Isolated Storage durant l'ex&eacute;cution.</li>
</ul>
<p>Pour plus d'informations, lisez <a href="http://msdn.microsoft.com/en-us/library/ff817009%28VS.92%29.aspx">Execution Model Best Practices for Windows Phone</a>.</p>
<h2></h2>
<h2>Voir aussi</h2>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/ff769557%28VS.92%29.aspx">Execution Model for Windows Phone</a></li>
</ul>
<hr />
<p><a href="#sommaire">Cliquez ici pour revenir au sommaire de la liste d&rsquo;articles</a></p>]]></content:encoded>
    </item>
  </channel>
</rss>