Skip to content

Conversation

@pictos
Copy link
Contributor

@pictos pictos commented Aug 1, 2025

Making this public will allow devs to filter and find the Window that has focus, it can make easier to show popups and perform some actions.

Related to #30762

Make IsActivated property public in Window.cs

The IsActivated property in the Microsoft.Maui.Controls namespace
was changed from internal to public. This increases its visibility,
allowing it to be accessed from outside the assembly.

Copilot AI review requested due to automatic review settings August 1, 2025 22:18
@pictos pictos requested a review from a team as a code owner August 1, 2025 22:18
@pictos pictos requested review from mattleibow and rmarinho August 1, 2025 22:18
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 makes the IsActivated property in the Window class publicly accessible by changing its visibility from internal to public. This allows external consumers of the Microsoft.Maui.Controls API to check whether a window is currently activated.

  • Changes the visibility modifier of the IsActivated property from internal to public

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Aug 1, 2025
@rmarinho
Copy link
Member

rmarinho commented Aug 4, 2025

Needs to update public api files ?

Copy link
Member

@mattleibow mattleibow left a comment

Choose a reason for hiding this comment

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

For public properties, this really should be a bindable readonly property

Also

Can you add somrthing to the mutli-window sample page

  • a binding to a label on that.

And maybe update/duplicate the tests here:

  • src/Controls/tests/Core.UnitTests/WindowsTests.cs
  • src/Controls/tests/DeviceTests/Elements/Window/WindowTests.Windows.cs

This is the wondow property on VisualElement, so ignore the name:

static readonly BindablePropertyKey WindowPropertyKey = BindableProperty.CreateReadOnly(
	nameof(Window), typeof(Window), typeof(VisualElement), null, propertyChanged: OnWindowChanged);

/// <summary>Bindable property for <see cref="Window"/>.</summary>
public static readonly BindableProperty WindowProperty = WindowPropertyKey.BindableProperty;

/// <summary>
/// Gets the <see cref="Window"/> that is associated with an element. This is a read-only bindable property.
/// </summary>
public Window Window => (Window)GetValue(WindowProperty);

/// <inheritdoc/>
Window IWindowController.Window
{
	get => (Window)GetValue(WindowProperty);
	set => SetValue(WindowPropertyKey, value);
}

I would expect something like this:

static readonly BindablePropertyKey IsActivatedPropertyKey = BindableProperty.CreateReadOnly(
	nameof(IsActivated), typeof(bool), typeof(Window), false);
public static readonly BindableProperty IsActivatedProperty = IsActivatedPropertyKey.BindableProperty;
public bool IsActivated
{
    get => (bool)GetValue(IsActivatedProperty)
    private set => SetValue(IsActivatedPropertyKey, value);
}

Also, we will need to remove the _isActivated field in window.cs.

@jfversluis jfversluis added s/pr-needs-author-input PR needs an update from the author area-controls-window Window labels Aug 5, 2025
@dotnet-policy-service
Copy link
Contributor

Hi @@pictos. We have added the "s/pr-needs-author-input" label to this issue, which indicates that we have an open question/action for you before we can take further action. This PRwill be closed automatically in 14 days if we do not hear back from you by then - please feel free to re-open it if you come back to this PR after that time.

@jfversluis jfversluis requested a review from mattleibow August 7, 2025 09:50
@jfversluis jfversluis added this to the .NET 10.0-rc1 milestone Aug 7, 2025
@jfversluis
Copy link
Member

jfversluis commented Aug 7, 2025

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@pictos
Copy link
Contributor Author

pictos commented Aug 7, 2025

BTW, is still missing DeviceTests, will implement it this week.
Can you remove the needs-author-input label?

@mattleibow mattleibow removed the s/pr-needs-author-input PR needs an update from the author label Aug 7, 2025
@mattleibow
Copy link
Member

This is great! Slowly bindable property-izing he world.

This will be nice to do binding to IsActivated.

Can you maybe also add a test for that using a binding to that property. Just to make sure that it does work.

Copy link
Member

@rmarinho rmarinho left a comment

Choose a reason for hiding this comment

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

Possible to add a DeviceTest ? clean up. the comment out code.

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@mattleibow
Copy link
Member

/rebase

pictos and others added 8 commits August 12, 2025 09:33
The `IsActivated` property in the `Microsoft.Maui.Controls` namespace
was changed from `internal` to `public`. This increases its visibility,
allowing it to be accessed from outside the assembly.
Changed Window.IsActivated to use a read-only BindableProperty and made its setter private. This restricts modification of the activation state to internal code, improving encapsulation and preventing external changes.
Changed Window.IsActivated setter to use IsActivatedPropertyKey for proper encapsulation. Added unit tests to verify window activation and deactivation behavior, including Appearing event handling. Included new using directives for async test support.
Copy link
Member

@mattleibow mattleibow left a comment

Choose a reason for hiding this comment

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

Matthew is super happy!

@mattleibow mattleibow added the p/0 Current heighest priority issues that we are targeting for a release. label Aug 12, 2025
@mattleibow
Copy link
Member

Bumped you to p/0, so you should get in the door for RC1.

@mattleibow
Copy link
Member

/azp run

@mattleibow mattleibow moved this from Todo to Approved in MAUI SDK Ongoing Aug 12, 2025
@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@MartyIX
Copy link
Contributor

MartyIX commented Aug 12, 2025

This is a super useful change. Kudos @pictos.

@PureWeen PureWeen merged commit f91b3aa into dotnet:net10.0 Aug 13, 2025
127 of 129 checks passed
@github-project-automation github-project-automation bot moved this from Approved to Done in MAUI SDK Ongoing Aug 13, 2025
@pictos pictos deleted the PublicWindowApi branch August 13, 2025 14:43
@github-actions github-actions bot locked and limited conversation to collaborators Sep 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-controls-window Window community ✨ Community Contribution p/0 Current heighest priority issues that we are targeting for a release.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

6 participants