Skip to content

Implement [BindableProperty] for MediaElement#2933

Merged
TheCodeTraveler merged 51 commits intoCommunityToolkit:mainfrom
ne0rrmatrix:Use-BindableProperty-for-MediaElement
Nov 30, 2025
Merged

Implement [BindableProperty] for MediaElement#2933
TheCodeTraveler merged 51 commits intoCommunityToolkit:mainfrom
ne0rrmatrix:Use-BindableProperty-for-MediaElement

Conversation

@ne0rrmatrix
Copy link
Copy Markdown
Member

@ne0rrmatrix ne0rrmatrix commented Nov 7, 2025

Description of Change

This pull request refactors the way bindable properties are declared and managed in the MediaElement and related media source classes. It transitions from manually defining BindableProperty fields and associated property wrappers to using the [BindableProperty] source generator attribute, which simplifies code and reduces boilerplate. Additionally, it updates project configuration to support source generators and analyzers.

Key changes include:

Refactoring to Source Generator Bindable Properties:

  • Replaces manual BindableProperty declarations in MediaElement, FileMediaSource, ResourceMediaSource, and UriMediaSource with [BindableProperty] attributes, reducing boilerplate and improving maintainability. This also updates property access patterns and documentation.

  • Removes now-unnecessary property wrappers and backing fields, relying on the generated partial properties instead.

Validation and Property Changed Logic:

  • Refactors the ValidateVolume method to match the new source generator signature and return a boolean, throwing an exception for out-of-range values.

  • Ensures property changed/callback methods are correctly linked via attribute parameters, maintaining previous behaviors for properties like Source, CurrentState, and Uri.

Project and Build Configuration:

  • Updates the CommunityToolkit.Maui.MediaElement.csproj to enable compiler-generated files output and adds a reference to the internal source generators project as an analyzer, supporting the new property declaration style.

These changes modernize the codebase, making it easier to maintain and reducing the risk of errors in property declaration and management.

As Discussed in our November 2025 Standup, this PR implements the [BindableProperty] attribute, replacing the manually created BindableProperties.

This PR also updates the BindableProperty Source Generator:

PR Checklist

Additional information

Copilot AI review requested due to automatic review settings November 23, 2025 00:20
Copy link
Copy Markdown
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

This PR migrates the MediaElement and MediaSource classes from manually-created BindableProperty declarations to using the [BindableProperty] source generator attribute. It also enhances the source generator to better support Int32, double, and other primitive types as default values.

Key Changes:

  • Replaced manual BindableProperty declarations with [BindableProperty] attributes across MediaElement and MediaSource classes
  • Enhanced AttributeExtensions.cs with improved type handling for Int32, double, TimeSpan, and Enum types
  • Added Range.cs as a polyfill for older framework versions

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 17 comments.

Show a summary per file
File Description
src/CommunityToolkit.Maui.SourceGenerators.Internal/Range.cs Added polyfill implementation for Index and Range types to support source generator in older frameworks
src/CommunityToolkit.Maui.SourceGenerators.Internal/Helpers/AttributeExtensions.cs Enhanced attribute value parsing with support for Int32, double, TimeSpan, and Enum types, though contains code duplication
src/CommunityToolkit.Maui.MediaElement/MediaSource/UriMediaSource.shared.cs Migrated Uri property from manual BindableProperty to [BindableProperty] attribute
src/CommunityToolkit.Maui.MediaElement/MediaSource/ResourceMediaSource.shared.cs Migrated Path property from manual BindableProperty to [BindableProperty] attribute
src/CommunityToolkit.Maui.MediaElement/MediaSource/FileMediaSource.shared.cs Migrated Path property from manual BindableProperty to [BindableProperty] attribute
src/CommunityToolkit.Maui.MediaElement/MediaElement.shared.cs Migrated all MediaElement bindable properties to use [BindableProperty] attribute, with several issues in default values, property callbacks, and interface implementations
src/CommunityToolkit.Maui.MediaElement/CommunityToolkit.Maui.MediaElement.csproj Added source generator project reference
samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementCollectionViewPage.xaml Added AndroidViewType attribute to MediaElement instance
samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementCarouselViewPage.xaml Added AndroidViewType attribute and reformatted MediaElement element

- `MediaHeight` and `MediaWidth`
- various default values
- AndroidViewType set to `init` for setter
Copilot AI review requested due to automatic review settings November 23, 2025 00:53
Copy link
Copy Markdown
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

Copilot reviewed 7 out of 8 changed files in this pull request and generated 8 comments.

Copilot AI review requested due to automatic review settings November 23, 2025 01:25
ne0rrmatrix and others added 2 commits November 22, 2025 17:25
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
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

Copilot reviewed 6 out of 9 changed files in this pull request and generated 16 comments.

ne0rrmatrix and others added 2 commits November 22, 2025 17:35
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings November 23, 2025 01:37
Copy link
Copy Markdown
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

Copilot reviewed 6 out of 9 changed files in this pull request and generated 3 comments.

Copy link
Copy Markdown
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI review requested due to automatic review settings November 29, 2025 18:18
Copy link
Copy Markdown
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

pictos
pictos previously requested changes Nov 29, 2025
Copy link
Copy Markdown
Member

@pictos pictos left a comment

Choose a reason for hiding this comment

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

Using the request change, since the code as it's right now will break at some point

ne0rrmatrix added a commit to ne0rrmatrix/MauiOld that referenced this pull request Nov 30, 2025
Copilot AI review requested due to automatic review settings November 30, 2025 20:32
Copy link
Copy Markdown
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI review requested due to automatic review settings November 30, 2025 21:29
Copy link
Copy Markdown
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI review requested due to automatic review settings November 30, 2025 21:30
Copy link
Copy Markdown
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
Collaborator

@TheCodeTraveler TheCodeTraveler left a comment

Choose a reason for hiding this comment

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

Thanks James!

I updated BindablePropertyAttributeSourceGenerator to support all accessibility types (private, private protected, protected, internal, protected internal and public), and I added Unit Tests for each setter accessibility type.

@pictos Could you give this a quick review too? Once you approve, we'll merge this 🙌

Copy link
Copy Markdown
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@TheCodeTraveler TheCodeTraveler dismissed pictos’s stale review November 30, 2025 21:52

Requested changes applied

Copy link
Copy Markdown
Member

@pictos pictos left a comment

Choose a reason for hiding this comment

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

LGTM

@TheCodeTraveler TheCodeTraveler enabled auto-merge (squash) November 30, 2025 22:52
@TheCodeTraveler TheCodeTraveler merged commit 7c46c3d into CommunityToolkit:main Nov 30, 2025
30 of 40 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Dec 2, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants