Skip to content

Commit

Permalink
Describe how to add images to shared project and reference them.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodja Trappe committed Dec 10, 2018
1 parent 32538b0 commit dd7932d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 8 additions & 0 deletions Demo/ImageModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ public ImageModule(UI ui) : base(ui)
Page = ui.NavigationPage(
ui.Page("Images",
ui.Stack().With(
ui.Label(@"
Add the images to your shared
project and set 'Build Action'
to EmbeddedRessource.
Also provide a 'Ressource ID'
which you can then reference
in UI.Image(string ressourceId)").Height(150).FontSize(22),
ui.Box().FillVertical(),
ui.Label("Designed by Starline / Freepik:"),
ui.Image("loremipsum.jpg")
Expand Down
5 changes: 3 additions & 2 deletions InterfaceBuilder/UI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public Label Label(string text = "")
HeightRequest = Theme.Sizes.NormalFont * 2,
VerticalTextAlignment = TextAlignment.Center,
Margin = new Thickness(Theme.Sizes.NormalFont, 0),
LineBreakMode = LineBreakMode.WordWrap,
}.Text(text);
}

Expand All @@ -32,7 +33,7 @@ public Button Button(string text = "")
};
}

public Image Image(string resourcename = "")
public Image Image(string resourceId = "")
{
var stackTrace = new System.Diagnostics.StackTrace();
var frame = stackTrace.GetFrames()[1];
Expand All @@ -41,7 +42,7 @@ public Image Image(string resourcename = "")
var methodsClass = method.DeclaringType;

return new Image {
Source = ImageSource.FromResource(resourcename, methodsClass.Assembly),
Source = ImageSource.FromResource(resourceId, methodsClass.Assembly),
Aspect = Aspect.AspectFit,
};
}
Expand Down

0 comments on commit dd7932d

Please sign in to comment.