C
C#4mo ago
Pandetthe

WFP InkCanvas hit test

Hi! I found a problem that my inkcanvas sometime is not being hit by VisualTreeHelper.Hittest on specific point.
1 Reply
Pandetthe
Pandetthe4mo ago
Everything works fine when InkCanvas is added to the page like this
Container.Children.Add(new InkCanvas());
Grid pageControl = new()
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Top,
Background = new ImageBrush(page.PageImage)
{
Stretch = Stretch.Uniform,
},
Width = page.PageImage.Width,
Height = page.PageImage.Height - 1,
Margin = i == pages.Count - 1 ? new(0) : new(0, 0, 0, 10)
};
Container.Children.Add(pageControl);
Container.Children.Add(new InkCanvas());
Grid pageControl = new()
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Top,
Background = new ImageBrush(page.PageImage)
{
Stretch = Stretch.Uniform,
},
Width = page.PageImage.Width,
Height = page.PageImage.Height - 1,
Margin = i == pages.Count - 1 ? new(0) : new(0, 0, 0, 10)
};
Container.Children.Add(pageControl);
But when we add ink canvas like this, its not working properly
Grid pageControl = new()
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Top,
Background = new ImageBrush(page.PageImage)
{
Stretch = Stretch.Uniform,
},
Width = page.PageImage.Width,
Height = page.PageImage.Height - 1,
Margin = i == pages.Count - 1 ? new(0) : new(0, 0, 0, 10)
};
pageControl.Children.Add(new InkCanvas());
Container.Children.Add(pageControl);
Grid pageControl = new()
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Top,
Background = new ImageBrush(page.PageImage)
{
Stretch = Stretch.Uniform,
},
Width = page.PageImage.Width,
Height = page.PageImage.Height - 1,
Margin = i == pages.Count - 1 ? new(0) : new(0, 0, 0, 10)
};
pageControl.Children.Add(new InkCanvas());
Container.Children.Add(pageControl);
Page is looking like this
<ScrollViewer x:Name="ContainerScrollViewer" CanContentScroll="False" VerticalScrollBarVisibility="Auto>
<StackPanel x:Name="Container" HorizontalAlignment="Stretch" VerticalAliggnment="Stretch" />
</ScrollViewer>
<ScrollViewer x:Name="ContainerScrollViewer" CanContentScroll="False" VerticalScrollBarVisibility="Auto>
<StackPanel x:Name="Container" HorizontalAlignment="Stretch" VerticalAliggnment="Stretch" />
</ScrollViewer>
Every 4 hittest or inputthittest misses inkcanvas And it's the same problem for routed events, that they don't reach inkcanvas every 4 raise And every hittest and raiseevents hits scrollviewer I have observed that It's happening only with inkcanvas that size was changed dynamically in code