Skip to content

Fix CameraView StopCameraPreviewCommand#3158

Open
zhitaop wants to merge 3 commits intoCommunityToolkit:mainfrom
zhitaop:fix/stop-camera-preview-command
Open

Fix CameraView StopCameraPreviewCommand#3158
zhitaop wants to merge 3 commits intoCommunityToolkit:mainfrom
zhitaop:fix/stop-camera-preview-command

Conversation

@zhitaop
Copy link
Contributor

@zhitaop zhitaop commented Mar 17, 2026

Description of Change

The CameraView.StopCameraPreviewCommand was changed from the type ICommand to Command<CancellationToken> in the commit 4ed306b

However, the method CameraView.StopCameraPreview() which the StopCameraPreviewCommand calls internally has a return type void instead of a Task. This means the StopCameraPreviewCommand does not need to use a CancelationToken.

The fix for this issue is to revert the signature of CameraView.StopCameraPreviewCommand to ICommand

Linked Issues

PR Checklist

  • Has a linked Issue, and the Issue has been approved(bug) or Championed (feature/proposal)
  • Has tests (if omitted, state reason in description)
  • Has samples (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Changes adhere to coding standard
  • Documentation created or updated: https://github.com/MicrosoftDocs/CommunityToolkit/pulls

Additional information

Copilot AI review requested due to automatic review settings March 17, 2026 11:43
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a runtime InvalidCastException when binding CameraView.StopCameraPreviewCommand by reverting the command’s public/bindable type back to a non-generic command interface, matching the underlying StopCameraPreview() void API.

Changes:

  • Change StopCameraPreviewCommandProperty bindable type from Command<CancellationToken> to ICommand.
  • Update the StopCameraPreviewCommand property to return ICommand and remove CancellationToken-related XML docs that no longer apply.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +140 to +142
/// Gets the <see cref="ICommand"/> that stops the camera preview.
/// </summary>
/// <remarks>
/// <see cref="StopCameraPreviewCommand"/> has a <see cref="Type"/> of Command&lt;CancellationToken&gt; which requires a <see cref="CancellationToken"/> as a CommandParameter. See <see cref="Command{CancellationToken}"/> and <see cref="System.Windows.Input.ICommand.Execute(object)"/> for more information on passing a <see cref="CancellationToken"/> into <see cref="Command{T}"/> as a CommandParameter
/// </remarks>
public Command<CancellationToken> StopCameraPreviewCommand => (Command<CancellationToken>)GetValue(StopCameraPreviewCommandProperty);
public ICommand StopCameraPreviewCommand => (ICommand)GetValue(StopCameraPreviewCommandProperty);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] CameraView StopCameraPreviewCommand is not working

2 participants