1

my idea is to create a listview with images, over each image I would like to insert a InkCanvas. I tried two ways and both have problems.

First way.

I created the listview with its DataTemplate:

<DataTemplate x:Name="ListViewItemTemplate">
        <Grid>
           <Image></Image>
           <InkCanvas></InkCanvas>
        </Grid>
</DataTemplate>

<ItemsPanelTemplate x:Name="ListItemsPanelTemplate">
        <VirtualizingStackPanel Orientation="Vertical">
            <VirtualizingStackPanel.ChildrenTransitions>
                <TransitionCollection/>
            </VirtualizingStackPanel.ChildrenTransitions>
        </VirtualizingStackPanel>
</ItemsPanelTemplate>

<ListView x:Name="list" 
    ItemTemplate="{StaticResource ListViewItemTemplate}"
    ItemsPanel="{StaticResource ListItemsPanelTemplate}">
</ListView>

c#:

 List<Image> pages = new List<Image>();
    list.ItemsSource = pages;

In this way, the listview uses virtualization, when I write in a inkview, the stroke is copied every 5 inkview. It's not good.

If I remove the virtualization:

<ItemsPanelTemplate x:Name="ListItemsPanelTemplate">
        <StackPanel Orientation="Vertical"/>
</ItemsPanelTemplate>

It occurs the problem of the second way. Written below.

Second way:

I created a usercontrol PageFormat for the DataTemplate like this:

<UserControl>
<Grid Background="White">
    <Image x:Name="image"></Image>
    <InkCanvas x:Name="ink" ></InkCanvas>
</Grid>
</UserControl>

<ListView x:Name="list" ></ListView>

c#:

List<PageFormat> pages= new List<PageFormat>();
list.ItemsSource = pages;

In this way I have the following problem:like in this question

When I create more than 125 InkCanvas I have a memory problem. I prefer the second way because I can play with the formatting of the page directly in a usercontrol, but I can not solve these problems.

I would like to solve the problem of generating InkCanvas the System.OutOfMemoryException error. How can I solve it? Thanks so much.

Community
  • 1
  • 1
Andrea485
  • 527
  • 2
  • 6
  • 16

1 Answers1

1

If you are 100% sure that InkCanvas is the cause of out of memory exceptions, you could do the following pseudo-system:

  • when a user is not editing an item, it should be persisted to disk/memory and a bitmap rendered and presented out of it.
  • when a user starts editing an item, de-serialize its data and realize it as an InkCanvas

i.e. use less resource-intensive types wherever it is appropriate

EDIT

Here's the solution to the fact that rendering an InkCanvas to a RenderTargetBitmap will produce a blank image:

https://mtaulty.com/2016/02/16/windows-10-uwp-inkcanvas-and-rendertargetbitmap/

(requires Win2D package)

aybe
  • 15,516
  • 9
  • 57
  • 105