You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: uwp/app-resources/images-tailored-for-scale-theme-contrast.md
+12-12Lines changed: 12 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,26 +17,26 @@ Some common qualifiers for images are [scale](tailor-resources-lang-scale-contra
17
17
## Qualify an image resource for scale, theme, and contrast
18
18
The default value for the `scale` qualifier is `scale-100`. So, these two variants are equivalent (they both provide an image at scale 100, or scale factor 1).
19
19
20
-
<blockquote>
20
+
21
21
<pre>
22
22
\Assets\Images\logo.png
23
23
\Assets\Images\logo.scale-100.png
24
24
</pre>
25
-
</blockquote>
25
+
26
26
27
27
28
28
You can use qualifiers in folder names instead of file names. That would be a better strategy if you have several asset files per qualifier. For purposes of illustration, these two variants are equivalent to the two above.
29
29
30
-
<blockquote>
30
+
31
31
<pre>
32
32
\Assets\Images\logo.png
33
33
\Assets\Images\scale-100\logo.png
34
34
</pre>
35
-
</blockquote>
35
+
36
36
37
37
Next is an example of how you can provide variants of an image resource—named `/Assets/Images/logo.png`—for different settings of display scale, theme, and high contrast. This example uses folder naming.
38
38
39
-
<blockquote>
39
+
40
40
<pre>
41
41
\Assets\Images\contrast-standard\theme-dark
42
42
\scale-100\logo.png
@@ -48,7 +48,7 @@ Next is an example of how you can provide variants of an image resource—na
48
48
\scale-100\logo.png
49
49
\scale-200\logo.png
50
50
</pre>
51
-
</blockquote>
51
+
52
52
53
53
## Reference an image or other asset from XAML markup and code
54
54
The name—or identifier—of an image resource is its path and file name with any and all qualifiers removed. If you name folders and/or files as in any of the examples in the previous section, then you have a single image resource and its name (as an absolute path) is `/Assets/Images/logo.png`. Here’s how you use that name in XAML markup.
@@ -98,29 +98,29 @@ Also see [Tile and toast support for language, scale, and high contrast](/window
98
98
## Qualify an image resource for targetsize
99
99
You can use the `scale` and `targetsize` qualifiers on different variants of the same image resource; but you can't use them both on a single variant of a resource. Also, you need to define at least one variant without a `TargetSize` qualifier. That variant must either define a value for `scale`, or let it default to `scale-100`. So, these two variants of the `/Assets/Square44x44Logo.png` resource are valid.
100
100
101
-
<blockquote>
101
+
102
102
<pre>
103
103
\Assets\Square44x44Logo.scale-200.png
104
104
\Assets\Square44x44Logo.targetsize-24.png
105
105
</pre>
106
-
</blockquote>
106
+
107
107
108
108
And these two variants are valid.
109
109
110
-
<blockquote>
110
+
111
111
<pre>
112
112
\Assets\Square44x44Logo.png // defaults to scale-100
## Refer to an image file from your app package manifest
126
126
If you name folders and/or files as in either of the two valid examples in the previous section, then you have a single app icon image resource and its name (as a relative path) is `Assets\Square44x44Logo.png`. In your app package manifest, simply refer to the resource by name. There's no need to use any URI scheme.
Copy file name to clipboardExpand all lines: uwp/app-resources/using-mrt-for-converted-desktop-apps-and-games.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -523,7 +523,7 @@ would not map well to MRT. A better structure would be a `Resources` directory w
523
523
For example, the application might have a set of custom UI commands (used for button labels etc.) in a simple text file named <span>ui.txt</span>,
524
524
laid out under a <span>UICommands</span> folder:
525
525
526
-
<blockquote>
526
+
527
527
<pre>
528
528
+ ProjectRoot
529
529
|--+ Strings
@@ -539,22 +539,22 @@ laid out under a <span>UICommands</span> folder:
539
539
|--- AppxManifest.xml
540
540
|--- ...rest of project...
541
541
</pre>
542
-
</blockquote>
542
+
543
543
544
544
#### Resource loading code
545
545
546
546
This article assumes that at some point in your code you want to locate the file that contains a localized resource, load it, and then use it. The APIs used to load the resources,
547
547
the APIs used to extract the resources, etc. are not important. In pseudocode, there are basically three steps:
548
548
549
-
<blockquote>
549
+
550
550
<pre>
551
551
set userLanguage = GetUsersPreferredLanguage()
552
552
set resourceFile = FindResourceFileForLanguage(MY_RESOURCE_NAME, userLanguage)
553
553
set resource = LoadResource(resourceFile)
554
554
555
555
// now use 'resource' however you want
556
556
</pre>
557
-
</blockquote>
557
+
558
558
559
559
MRT only requires changing the first two steps in this process - how you determine the best candidate resources and how you locate them. It doesn't require you to change how you load
560
560
or use the resources (although it provides facilities for doing that if you want to take advantage of them).
@@ -578,7 +578,7 @@ this example, the file-based resources vs. the string resources)
578
578
579
579
In pseudo-code, the way you would resolve a given resource file name (like `UICommands\ui.txt` in the sample above) is as follows:
580
580
581
-
<blockquote>
581
+
582
582
<pre>
583
583
// Get the ResourceContext that applies to this app
584
584
set resourceContext = ResourceContext.GetForViewIndependentUse()
@@ -598,7 +598,7 @@ set bestCandidate = desiredResource.Resolve(resourceContext)
598
598
599
599
// Get the string value (the filename) from the ResourceCandidate
600
600
set absoluteFileName = bestCandidate.ValueAsString
601
-
</blockquote>
601
+
602
602
</pre>
603
603
604
604
Note in particular that the code does **not** request a specific language folder - like `UICommands\en-US\ui.txt` - even though that is how the files exist on-disk. Instead, it
@@ -618,7 +618,7 @@ user doesn't have the language listed in their preferences).
618
618
619
619
For example, imagine a .NET application with the following layout, where all the files exist under the `MainApp` folder:
620
620
621
-
<blockquote>
621
+
622
622
<pre>
623
623
+ MainApp
624
624
|--+ en-us
@@ -629,11 +629,11 @@ For example, imagine a .NET application with the following layout, where all the
629
629
| \--- MainApp.resources.dll
630
630
\--- MainApp.exe
631
631
</pre>
632
-
</blockquote>
632
+
633
633
634
634
After conversion to .appx, the layout will look something like this, assuming `en-US` was the default language and the user has both German and French listed in their language list:
635
635
636
-
<blockquote>
636
+
637
637
<pre>
638
638
+ WindowsAppsRoot
639
639
|--+ MainApp_neutral
@@ -647,7 +647,7 @@ After conversion to .appx, the layout will look something like this, assuming `e
647
647
\--+ fr-fr
648
648
\--- <span>MainApp.resources.dll</span>
649
649
</pre>
650
-
</blockquote>
650
+
651
651
652
652
Because the localized resources no longer exist in sub-directories underneath the main executable's install location, the built-in .NET resource resolution fails. Luckily, .NET has
653
653
a well-defined mechanism for handling failed assembly load attempts - the `AssemblyResolve` event. A .NET app using MRT must register for this event and provide the missing assembly
0 commit comments