I'm working on a UWP using Visual Studio Community 2015. I created a blank project, added a button and RichEditBox. I'm trying to insert an image in RichEditBox from local resources, but I only insert a blank placeholder (with the desired size of the image). No errors are thrown.
Here is the code behind:
private async void Button_Click(object sender, RoutedEventArgs e)
{
Uri imageUri = new Uri("ms-appx:///Assets/StoreLogo.png");
using (IRandomAccessStream ras = await RandomAccessStreamReference.CreateFromUri(imageUri).OpenReadAsync())
{
box.Document.Selection.InsertImage(64, 64, 0, VerticalCharacterAlignment.Baseline, "img", ras);
}
}
Here is the xaml:
<Button Content="Insert image" Click="Button_Click"/>
<RichEditBox Name="box" Height="200"/>
Build action of StoreLogo.png is "content", I tried to copy the image to the output directory which made no difference.
What could be the problem here? What's the correct way to do this?