Skip to content

Conversation

@ne0rrmatrix
Copy link
Member

Description of Change

This adds support for [BindableProperties] to Layouts in CommunityToolkitMaui.
This PR is blocked until support is added for BindableProperties.AddAttached as it is required to complete this PR. There are several classes StateContainer, StateContainerController and StateView that require addition updates to our internal source generator to complete this.

  • Fixes #

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

Blocked until support for Attached bindable properties is added.

@ne0rrmatrix ne0rrmatrix marked this pull request as ready for review December 19, 2025 20:56
@TheCodeTraveler TheCodeTraveler marked this pull request as draft December 20, 2025 15:47
Copy link
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!

Could you also please create a [ClassName]Defaults.shared.cs class for each of these Views in CommunityToolkit.Maui.Core/Defaults/ and also add a Unit Test for each called EnsureDefaults that verifies the default value for each property in the class equals the expected default value?

Here's an example that I added for FadeAnimation in the recent PR:

static class FadeAnimationDefaults
{
public const uint Length = 300u;
public const double Opacity = 0.3;
}

[Fact]
public void EnsureDefaults()
{
// Arrange
var animation = new FadeAnimation();
// Act // Assert
Assert.Equal(BaseAnimationDefaults.Easing, animation.Easing);
Assert.Equal(FadeAnimationDefaults.Length, animation.Length);
Assert.Equal(FadeAnimationDefaults.Opacity, animation.Opacity);
}

We should've created [ClassName]Defaults.shared.cs and implemented these Unit Tests when originally creating every control in CommunityToolkit.Maui. But now that we're going back and editing every control to implement [BindableProperty], I've found that this is a great time to clean up our codebase and implement these!

@ne0rrmatrix
Copy link
Member Author

Thanks James!

Could you also please create a [ClassName]Defaults.shared.cs class for each of these Views in CommunityToolkit.Maui.Core/Defaults/ and also add a Unit Test for each called EnsureDefaults that verifies the default value for each property in the class equals the expected default value?

Here's an example that I added for FadeAnimation in the recent PR:

static class FadeAnimationDefaults
{
public const uint Length = 300u;
public const double Opacity = 0.3;
}

[Fact]
public void EnsureDefaults()
{
// Arrange
var animation = new FadeAnimation();
// Act // Assert
Assert.Equal(BaseAnimationDefaults.Easing, animation.Easing);
Assert.Equal(FadeAnimationDefaults.Length, animation.Length);
Assert.Equal(FadeAnimationDefaults.Opacity, animation.Opacity);
}

We should've created [ClassName]Defaults.shared.cs and implemented these Unit Tests when originally creating every control in CommunityToolkit.Maui. But now that we're going back and editing every control to implement [BindableProperty], I've found that this is a great time to clean up our codebase and implement these!

Sounds like a plan. I will make the requested changes.

Copilot AI review requested due to automatic review settings January 10, 2026 02:09
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

This PR refactors two layout classes (UniformItemsLayout and DockLayout) to use modern [BindableProperty] partial properties instead of traditional BindableProperty definitions. The refactoring introduces default value constants in new static classes and adds unit tests to verify default values are correctly set.

Key changes:

  • Migrates bindable properties to use source-generated partial properties with [BindableProperty] attributes
  • Extracts default values into centralized UniformItemLayoutDefaults and DockLayoutDefaults classes
  • Adds unit tests to validate default property values

Reviewed changes

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

Show a summary per file
File Description
UniformItemsLayout.shared.cs Refactored MaxRows and MaxColumns properties to use [BindableProperty] with partial properties; moved validation to property changed callbacks
DockLayout.shared.cs Refactored ShouldExpandLastChild, HorizontalSpacing, and VerticalSpacing properties to use [BindableProperty] with partial properties
UniformItemLayoutDefaults.shared.cs New static class defining default constants for UniformItemsLayout properties
DockLayoutDefaults.shared.cs New static class defining default constants for DockLayout properties
UniformItemsLayoutTests.cs Added test to verify default property values; added necessary namespace import
DockLayoutTests.cs Added test to verify default property values

@TheCodeTraveler TheCodeTraveler marked this pull request as ready for review January 10, 2026 21:19
Copilot AI review requested due to automatic review settings January 10, 2026 21:31
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.

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 January 10, 2026 21:35
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.

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

Copy link
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! Let's go ahead and merge this.

I've included the Attached Bindable Property updates for DockLayout in my [AttachedBindableProperty] PR: #3024

@TheCodeTraveler TheCodeTraveler merged commit 8051299 into CommunityToolkit:main Jan 10, 2026
21 of 24 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jan 12, 2026
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.

2 participants