Issue with InkCanvas in UWP: Working on Windows 11 but Not on Windows 10

71 views Asked by At

I've developed an image editor using the InkCanvas control in my UWP (Universal Windows Platform) application. Surprisingly, it works perfectly fine on Windows 11. However, when testing the app on Windows 10, I encounter an issue where the InkCanvas doesn't draw on the image.

Although the ink toolbar is visible and functional, allowing users to select colors and tools, the actual drawing on the image doesn't happen. If anyone has encountered a similar problem or has insights on how to resolve this issue, I would greatly appreciate your help.

this is a snippet of the XAML component containing the InkCanvas:

<ContentDialog
    x:Class="eseua.Views.ImageEditorDialog"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:helpers="using:eseua.Helpers"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Margin="5"
    CornerRadius="{StaticResource OverlayCornerRadius}"
    FullSizeDesired="True"
    PrimaryButtonStyle="{StaticResource DefaultButtonStyle}"
    PrimaryButtonText="{helpers:ResourceString Name=EditImageDialog_PrimaryButtonText}"
    SecondaryButtonStyle="{StaticResource ThemeAwareContentDialogSecondaryButtonStyle}"
    SecondaryButtonText="{helpers:ResourceString Name=Logout_Dialog_No}"
    mc:Ignorable="d">
    <ContentDialog.Resources>
        <x:Double x:Key="ContentDialogWidth">700</x:Double>
        <x:Double x:Key="ContentDialogMinWidth">200</x:Double>
        <x:Double x:Key="ContentDialogMaxWidth">1000</x:Double>
    </ContentDialog.Resources>
    <Grid
        x:Name="img_grid"
        HorizontalAlignment="Stretch"
        VerticalAlignment="Center">

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <Grid x:Name="img_t" Grid.Row="1">
            <Image x:Name="img" Source="{x:Bind ViewModel.FilePath, Mode=OneWay}" />
            <InkCanvas
                x:Name="img_inkcanvas"
                HorizontalAlignment="Stretch"
                VerticalAlignment="Stretch" />
        </Grid>
        <Grid Grid.Row="0">
            <InkToolbar
                x:Name="img_inktoolbar"
                VerticalAlignment="Top"
                TargetInkCanvas="{x:Bind img_inkcanvas}" />
        </Grid>
    </Grid>
</ContentDialog>

and this is my code behind

namespace eseua.Views
{
    public sealed partial class ImageEditorDialog : ContentDialog
    {
        internal ImageEditorDialogViewModel ViewModel => DataContext as ImageEditorDialogViewModel;

        private readonly IUsageDataService _usageDataService;
        private bool isSaved = false;
        public ImageEditorDialog()
        {
            this.InitializeComponent();
            _usageDataService = ((PrismApplication)Application.Current).Container.Resolve<IUsageDataService>();
            var themeBinding = new Binding { Source = ThemeAwareHelper.Instance, Path = new PropertyPath("Theme") };
            SetBinding(RequestedThemeProperty, themeBinding);
            img_inkcanvas.InkPresenter.InputDeviceTypes =
                    Windows.UI.Core.CoreInputDeviceTypes.Mouse |
                    Windows.UI.Core.CoreInputDeviceTypes.Pen;
            this.Closing += ImageEditorDialog_Closing;

            this.PrimaryButtonClick += SaveEditedImage;
        }
        private async void SaveEditedImage(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            try
            {
                img_inktoolbar.Visibility = Visibility.Collapsed;
                img_inktoolbar.Opacity = 0;
                RenderTargetBitmap bitmap = await RenderBitmapAsync(img_t);
                await ViewModel.SaveBitmapToFile(bitmap, ViewModel.FilePath);
                sender.Hide();
            }
            finally
            {
                isSaved = true;
            }
        }
}
}

the device I test the app on is Windows 10 Build 19045 version 22H2

0

There are 0 answers