I'm trying to load a vector image in a zoomable ScrollViewer, works great on my laptop, but very slow on a tablet when zooming/unzooming. The UI is frozen during image rendering.
My image was converted from svg to xaml file with Inkscape. (~2,37 MB)
C#
public MainPage()
{
this.InitializeComponent();
this.Loaded += MainPage_Loaded;
}
async void MainPage_Loaded(object sender, RoutedEventArgs e)
{
string fileContent;
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(@"ms-appx:///Images/plan.xaml"));
using (StreamReader sRead = new StreamReader(await file.OpenStreamForReadAsync()))
fileContent = await sRead.ReadToEndAsync();
var xamlRead = XamlReader.Load(fileContent) as Canvas;
ImgMainGrid.Height = xamlRead.Height;
ImgMainGrid.Width = xamlRead.Width;
ImgMainGrid.Children.Add(xamlRead);
}
xaml
<ScrollViewer Grid.Row="1" x:Name="scrl" ZoomMode="Enabled" HorizontalScrollMode="Enabled" VerticalScrollMode="Enabled" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" MinZoomFactor="1">
<Grid x:Name="ImgMainGrid" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
</ScrollViewer>
How can i render the Canvas in background ? (without blocking the UI). If it's not possible, how can i handle this rendering to add a ProgressBar while rendering ?