Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xaml Unsupported MouseAction.None value #8842

Open
MauNguyenVan opened this issue Feb 25, 2024 · 6 comments
Open

Xaml Unsupported MouseAction.None value #8842

MauNguyenVan opened this issue Feb 25, 2024 · 6 comments
Assignees
Labels
Investigate Requires further investigation by the WPF team.

Comments

@MauNguyenVan
Copy link

MauNguyenVan commented Feb 25, 2024

Description

Bug in parsing Xaml for MouseAction .None
NotSupportedException: Unsupported MouseAction 'NONE'.

I use Win 10, VS 2022 17.9.1
SDK : .NET 8.0

Reproduction Steps

  • Create new Wpf App.
  • in Xaml Editer, add <MouseBinding MouseAction="None" Command="{Binding cmd}"/> in grid.
<Window x:Class="WpfApp.MainWindow"
        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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800" >

    <Grid>
        <Grid.InputBindings>
            <MouseBinding MouseAction="None" Command="{Binding cmd}"/>//Bug here when use MouseAction="None", in API docs, MouseAction.None is a valid value, but in xaml can't convert and emit an error , =>when try run app , it still run  but throw an Ex
        </Grid.InputBindings>
    </Grid>
</Window>

Expected behavior

No Error. None is a valid value. Compile and run normal
ref docs: https://learn.microsoft.com/en-us/dotnet/api/system.windows.input.mouseaction?view=windowsdesktop-8.0

Actual behavior

Error XLS0431 Invalid value for property 'MouseAction': 'None'

image

then run the app, it will occur an exception.

image

Regression?

No response

Known Workarounds

No response

Impact

No response

Configuration

No response

Other information

No response

@miloush
Copy link
Contributor

miloush commented Feb 25, 2024

Technically the documentation says that None is a valid enum value. It does not say whether it is valid in this context (which it happens to be), neither it says how the value should be represented as string or in XAML. If you look at the MouseActionConverter, you can see that the corresponding string for the None value is an empty string.

It probably wouldn't hurt to make it recognize "None", but it would be a breaking change to produce "None" when converting to string.

That said, using None does not make much sense here, the mouse gesture will never match anything.

@dipeshmsft dipeshmsft added the Investigate Requires further investigation by the WPF team. label Feb 26, 2024
@MauNguyenVan
Copy link
Author

Visual Studio emits it as an error, But you can build normally, then Bomb, throws an exception. It 's seem buggy

@miloush
Copy link
Contributor

miloush commented Feb 26, 2024

That seems expected. It's the designer in Visual Studio that tries to load the XAML. Building does not load the XAML, it just stores it in the assembly as a resource. When you run the application, it reads the resource and tries to load it. Loading is the bit that tries to convert the values and fails.

@MauNguyenVan
Copy link
Author

IMO, In XAML MouseAction="None" should be allowed. it seems more reasonable when treading equally as other members

@miloush
Copy link
Contributor

miloush commented Mar 3, 2024

PRs are welcome!

@MauNguyenVan
Copy link
Author

PRs are welcome!

Hello, I have created a PR. please review my code changed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Investigate Requires further investigation by the WPF team.
Projects
None yet
Development

No branches or pull requests

4 participants