{"id":366,"date":"2011-07-31T19:58:36","date_gmt":"2011-07-31T19:58:36","guid":{"rendered":"http:\/\/nestor.nestasoft.fr\/?p=366"},"modified":"2011-08-08T21:06:09","modified_gmt":"2011-08-08T21:06:09","slug":"xaml-astuces-n%c2%b01-staticresource","status":"publish","type":"post","link":"https:\/\/nestasoft.fr\/?p=366","title":{"rendered":"Xaml(WPF &#8211; Silverlight) : Astuce 1 &#8211; StaticResource"},"content":{"rendered":"<p><img decoding=\"async\" class=\"alignleft\" src=\"http:\/\/www.nestor.nestasoft.fr\/wp-content\/uploads\/2011\/07\/xa1.JPG\" alt=\"Xaml\" width=\"25%\" height=\"20%\" \/><\/p>\n<p>Pour rappel, <b>XAML<\/b> pour Extensible Application Markup Language est un language de type XML de description d&rsquo;interface utilis\u00e9 dans Silverlight et WPF entendez Windows Presentation Foundation les technologies RIA &#038; RDA de Microsoft.<br \/>\n<br \/>\n<!--more--><\/p>\n<hr\/>\n<p><\/p>\n<p>Tout bon d\u00e9veloppeur sait qu&rsquo;il est primordiale (gain de temps, \u00e9volution du code) de r\u00e9duire le d\u00e9couplage entre les diff\u00e9rentes applications \/ Module d&rsquo;un projet.<\/p>\n<p>Prenons par exemple les fichiers de Style.<br \/>\nEn HTML l&rsquo;utilisation ad\u00e9quat serait de cr\u00e9er un fichier <b>header.htm<\/b> dans lequel on fait appel \u00e0 notre fichier de style.css. En PHP MVC, on serait tenter de le faire dans la Vue Principale de l&rsquo;application; En ASP.NET MVC 2 dans le <b>Site.Master<\/b>. Dans une application Silverligth ou WPF  on le d\u00e9clarera dans le fichier <b>App.xaml<\/b>:<\/p>\n<pre class=\"brush:css\">\r\n<Application.Resources>\r\n        <ResourceDictionary>\r\n            <ResourceDictionary.MergedDictionaries>\r\n                <ResourceDictionary Source=\"Assets\/Styles.xaml\"\/> \r\n            <\/ResourceDictionary.MergedDictionaries>\r\n        <\/ResourceDictionary>                \r\n    <\/Application.Resources>\r\n<\/pre>\n<p>Le <H2>StaticResource<\/H2><br \/>\nFournit une valeur pour tout attribut de propri\u00e9t\u00e9 XAML en recherchant une r\u00e9f\u00e9rence \u00e0 une ressource d\u00e9j\u00e0 d\u00e9finie.<\/p>\n<h3>Exemple d&rsquo;utilisation<\/h3>\n<p>Ayant fait fait appel au fichier Style.xaml du folder Asset, dans notre page principale Silverligth, le MainPage.xaml on peut \u00e9crire:<\/p>\n<pre class=\"brush:csharp\">\r\n<navigation:Page Style=\"{StaticResource MainPageStyle}\">   \r\n<\/navigation:Page>\r\n<\/pre>\n<p>(MainPageStyle ayant \u00e9t\u00e9 d\u00e9finit dans Style.xaml).<\/p>\n<p>On peut ainsi appeler toutes nos Style en pr\u00e9cisant le nom de la <b>Key<\/b> comme ceci:<\/p>\n<p><b>Dans la page Xaml<\/b><\/p>\n<pre class=\"brush:csharp\">\r\n<Grid Style=\"{StaticResource NavigationGridStyle}\" >...<\/Grid>\r\n<\/pre>\n<p><b>Dans le fichier Style.xaml<\/b><\/p>\n<pre class=\"brush:csharp\">\r\n        <Style x:Key=\"MainPageStyle\" TargetType=\"UserControl\">\r\n\t        <Setter Property=\"FontFamily\" Value=\"Verdana\"><\/Setter>\r\n        <\/Style>\r\n<\/pre>\n<p>Fin de l&rsquo;astuce n\u00b01 \ud83d\ude42<br \/>\nRDV next step!<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_366\" class=\"pvc_stats all  \" data-element-id=\"366\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/nestasoft.fr\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Pour rappel, XAML pour Extensible Application Markup Language est un language de type XML de description d&rsquo;interface utilis\u00e9 dans Silverlight et WPF entendez Windows Presentation Foundation les technologies RIA &#038; RDA de Microsoft.<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_366\" class=\"pvc_stats all  \" data-element-id=\"366\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/nestasoft.fr\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-366","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/nestasoft.fr\/index.php?rest_route=\/wp\/v2\/posts\/366","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nestasoft.fr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nestasoft.fr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nestasoft.fr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nestasoft.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=366"}],"version-history":[{"count":60,"href":"https:\/\/nestasoft.fr\/index.php?rest_route=\/wp\/v2\/posts\/366\/revisions"}],"predecessor-version":[{"id":420,"href":"https:\/\/nestasoft.fr\/index.php?rest_route=\/wp\/v2\/posts\/366\/revisions\/420"}],"wp:attachment":[{"href":"https:\/\/nestasoft.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=366"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nestasoft.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=366"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nestasoft.fr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=366"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}