In a UWP project, I put an InkCanvas
in each ListViewItem. But when the items count exceed 126, I got an XamlParseException, which complained:
Cannot create instance of type 'Windows.UI.Xaml.Controls.InkCanvas
'
Below is the naïve code snippets:
<Page x:Class="App9.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<ListView ItemsSource="{x:Bind Items, Mode=OneWay}">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<InkCanvas />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
</Grid>
</Page>
code behind:
public sealed partial class MainPage : Page
{
public ObservableCollection<int> Items { get; }
public MainPage()
{
this.Items = new ObservableCollection<int>();
for (int i = 0; i < 130; i++)
{
this.Items.Add(i);
}
InitializeComponent();
}
}
(Please note: to test the upper limit, I've changed the default ItemsPanel
of ListView)
These above code is pretty simple, so it seems nothing is wrong with the code. Could it be there is a upper limit one can create InkCanvas
?
Edit: I've tested to create the InkCanvas in code behind like this:
for (int i = 0; i < 130; i++)
{
this.lvw.Items.Add(new InkCanvas());
}
which I got a different runtime error: System.OutOfMemoryException: 'Insufficient memory to continue the execution of the program.'
But by inspect Task Manager, I can see an app contains 100 instance of InkCanvas only take no more than 40mb memory. It is very confusing.