[Windows] Fix SearchBar icon not updating on runtime theme changes#16
Draft
[Windows] Fix SearchBar icon not updating on runtime theme changes#16
Conversation
Co-authored-by: devanathan-vaithiyanathan <114395405+devanathan-vaithiyanathan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] [Windows] Facing issues with the SearchBar's search icon when applying Dark theme.
[Windows] Fix SearchBar icon not updating on runtime theme changes
Jul 16, 2025
| platformView.LostFocus -= OnLostFocus; | ||
|
|
||
| // Unsubscribe from theme changes | ||
| if (Application.Current is not null) |
There was a problem hiding this comment.
@copilot , In the handler, when accessing the Application, it refers to the native Application. I need to get the .NET MAUI theme, and when the theme changes, I want to update the search icon color based on the current theme.
Author
There was a problem hiding this comment.
You're absolutely right! I was accessing the native Windows Application instead of the MAUI Application. I've updated the code to use Microsoft.Maui.Controls.Application.Current which properly accesses the .NET MAUI theme system. This ensures the SearchBar icon updates correctly when the MAUI theme changes at runtime. Fixed in commit 34edd4b.
…tive Windows Application Co-authored-by: devanathan-vaithiyanathan <114395405+devanathan-vaithiyanathan@users.noreply.github.com>
546914f to
513755f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Description
Fixes an issue where the SearchBar's search icon does not change color when switching themes at runtime on Windows.
Problem
The SearchBar uses an AutoSuggestBox with a SymbolIcon as the QueryIcon on Windows. This icon was created once during platform view creation and never updated when the application theme changed, causing it to retain its original color scheme even after switching between light and dark themes.
Solution
Added theme change detection to the SearchBarHandler on Windows:
Application.Current.RequestedThemeChangedevent inConnectHandlerDisconnectHandlerto prevent memory leaksCode Changes
Testing
To test the fix:
Application.Current.UserAppTheme = AppTheme.DarkImpact
Fixes #15.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
4vyvsblobprodcus361.vsblob.vsassets.iodotnet test src/Controls/tests/DeviceTests/ --filter SearchBarTests --configuration Debug --verbosity minimal(dns block)4zjvsblobprodcus390.vsblob.vsassets.iodotnet test src/Controls/tests/DeviceTests/ --filter SearchBarTests --configuration Debug --verbosity minimal(dns block)gervsblobprodcus329.vsblob.vsassets.iodotnet test src/Controls/tests/DeviceTests/ --filter SearchBarTests --configuration Debug --verbosity minimal(dns block)jd4vsblobprodcus366.vsblob.vsassets.iodotnet test src/Controls/tests/DeviceTests/ --filter SearchBarTests --configuration Debug --verbosity minimal(dns block)kxqvsblobprodcus376.vsblob.vsassets.iodotnet test src/Controls/tests/DeviceTests/ --filter SearchBarTests --configuration Debug --verbosity minimal(dns block)o3svsblobprodcus318.vsblob.vsassets.iodotnet test src/Controls/tests/DeviceTests/ --filter SearchBarTests --configuration Debug --verbosity minimal(dns block)rcxvsblobprodcus328.vsblob.vsassets.iodotnet test src/Controls/tests/DeviceTests/ --filter SearchBarTests --configuration Debug --verbosity minimal(dns block)tphvsblobprodcus375.vsblob.vsassets.iodotnet test src/Controls/tests/DeviceTests/ --filter SearchBarTests --configuration Debug --verbosity minimal(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.