Skip to content

Commit

Permalink
docs: add referencing assets from code
Browse files Browse the repository at this point in the history
  • Loading branch information
ajpinedam committed Oct 26, 2024
1 parent eb4ecae commit dd0be9e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions doc/articles/features/working-with-assets.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,30 @@ Or

For Uno's latest project template where images are saved in the `Images` folder.

### Referencing an asset from code

You can also reference assets from code using the `ms-appx:///` scheme. For example:

```xaml
<Image x:Name="MyImage" />
```

```csharp
// from XAML code behind
MyImage.Source = "ms-appx:///Assets/MyImage.png";
```

or using bindings:

```csharp
// from a ViewModel
public string ImagePath { get; set ;} = "ms-appx:///Assets/MyImage.png";
```

```xaml
<Image Source="{x:Bind ImagePath}" />
```

You can also get assets directly using [StorageFile.GetFileFromApplicationUriAsync](xref:Uno.Features.FileManagement#support-for-storagefilegetfilefromapplicationuriasync).

## Qualify an asset
Expand Down

0 comments on commit dd0be9e

Please sign in to comment.