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

[BUG] Cannot capture image with CameraView using just MVVM #1993

Open
2 tasks done
jfversluis opened this issue Jul 2, 2024 · 1 comment
Open
2 tasks done

[BUG] Cannot capture image with CameraView using just MVVM #1993

jfversluis opened this issue Jul 2, 2024 · 1 comment
Labels
bug Something isn't working Camera 📸 Issue/PR associated with the Camera package

Comments

@jfversluis
Copy link
Member

Is there an existing issue for this?

  • I have searched the existing issues

Did you read the "Reporting a bug" section on Contributing file?

Current Behavior

As outlined in our docs we can use the CaptureImageCommand to capture an image while using the MVVM pattern in our .NET MAUI app.

However, to access the actual media that was captured we need to subscribe to the MediaCaptured event. And by having to use an event suddenly I am breaking the MVVM pattern.

Expected Behavior

We need to have a way of also capturing the media in an MVVM fashion to not force people into bad patterns.

Steps To Reproduce

N/A

Link to public reproduction project repository

https://github.com/CommunityToolkit/Maui

Environment

- .NET MAUI CommunityToolkit Camera: 1.0.2
- OS: N/A
- .NET MAUI: 8.0.61

Anything else?

Additionally I think we may want to consider giving the CaptureImageCommand a default value for the CancellationToken or have an override without it. This makes consuming in XAML a bit harder.

@jfversluis jfversluis added bug Something isn't working needs discussion Discuss it on the next Monthly standup Camera 📸 Issue/PR associated with the Camera package labels Jul 2, 2024
@polincev
Copy link

polincev commented Jul 11, 2024

For anybody stumbling upon this issue, a functional work-around I'm currently using is the EventToCommandBehavior from the Community Toolkit. This doesn't require any code-behind and propagates the captured media to the ViewModel.

Here is a sample XAML that maps the MediaCaptured event to a command named MediaCapturedCommand:

<toolkit:CameraView.Behaviors>
    <toolkit:EventToCommandBehavior
        EventName="MediaCaptured"
        x:TypeArguments="toolkit:MediaCapturedEventArgs"
        Command="{Binding BindingContext.MediaCapturedCommand, Source={x:Reference Camera}}"/>
</toolkit:CameraView.Behaviors>

The Command needs to accept a parameter of type MediaCapturedEventArgs in this case.

** EDIT **

Just to avoid any confusion, the "Camera" which is referenced in the Binding Source is the name I have assigned to the ContentPage (x:Name="Camera")

@TheCodeTraveler TheCodeTraveler removed the needs discussion Discuss it on the next Monthly standup label Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Camera 📸 Issue/PR associated with the Camera package
Projects
None yet
Development

No branches or pull requests

3 participants