Fix VisualStateManager theme changes not applying properly with AppThemeBinding - #8
Fix VisualStateManager theme changes not applying properly with AppThemeBinding#8praveenkumarkarunanithi with Copilot wants to merge 4 commits into
Conversation
…e on theme changes Co-authored-by: praveenkumarkarunanithi <100338903+praveenkumarkarunanithi@users.noreply.github.com>
Co-authored-by: praveenkumarkarunanithi <100338903+praveenkumarkarunanithi@users.noreply.github.com>
|
@copilot , your fix is not working in resolving this issue. Specific Technical Details: DynamicResource Problem: DynamicResource setters in visual states are only applied during state transitions. When resources change (theme change), these setters retain their old cached values because no new state transition occurs. Inconsistent Behavior: Only the most recently interacted control gets updated colors because that control has fresh setter instances created during its recent state change, while other controls retain stale setter instances. |
…tead of calling GoToState Co-authored-by: praveenkumarkarunanithi <100338903+praveenkumarkarunanithi@users.noreply.github.com>
You're absolutely right about the root cause. The issue was that I've fixed this by changing the approach in The fix is in commit a5e92e9. Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
…tnet#33071) App crashes because of changing a shared Drawable on the fly. I found out it is the SearchBar. It only happens on Android and in large apps with lots of screens. Unfortunately I can't reproduce it in the TestSuite. But by reading the docs of Android this crash is common and caused by changing a Drawable which is still referenced. With a custom SearchBarHandler the issues is resolved. ```Backtrace (top frames): #00 pc 00000000006b8694 /system/lib64/libhwui.so android::getRootAlpha(_JNIEnv*, _jobject*, long) +4 #1 pc 0000000002256c90 /memfd:jit-cache (deleted) art_jni_trampoline +112 #2 pc 000000000223bc4c /memfd:jit-cache (deleted) android.graphics.drawable.VectorDrawable.-$$Nest$smnGetRootAlpha +108 dotnet#3 pc 000000000223bb20 /memfd:jit-cache (deleted) android.graphics.drawable.VectorDrawable$VectorDrawableState.getAlpha +144 #4 pc 00000000025c50e0 /memfd:jit-cache (deleted) android.graphics.drawable.VectorDrawable.getAlpha +128 #5 pc 00000000025c4f9c /memfd:jit-cache (deleted) android.graphics.drawable.VectorDrawable.getOpacity +124 #6 pc 00000000025c1ea8 /memfd:jit-cache (deleted) android.widget.ImageView.isOpaque +152 #7 pc 000000000227979c /memfd:jit-cache (deleted) android.view.View.invalidateInternal +428 #8 pc 00000000025c4790 /memfd:jit-cache (deleted) android.widget.ImageView.invalidateDrawable +256 #9 pc 000000000224419c /memfd:jit-cache (deleted) android.graphics.drawable.Drawable.invalidateSelf +156 #10 pc 000000000260e710 /memfd:jit-cache (deleted) android.graphics.drawable.VectorDrawable.setTintList +192 #11 pc 00000000025d0094 /memfd:jit-cache (deleted) **android.graphics.drawable.Drawable.setTint +148** ``` ### Description of Change - Changes tinting of Androids SearchBar to unified setTint instead of setColorFilter - Mutates the drawable before setting the tint. ### Issues Fixed Issue is fixed with a custom handler for now. Fixes dotnet#33070
Problem
Dynamic theme changes were not applying properly when using VisualStateManager with custom controls that contain AppThemeBinding values in their visual state setters. The issue manifested as:
Root Cause
When a VisualState is active and contains setters with AppThemeBinding values, theme changes were not being propagated to these bindings. The
AppThemeBindingclass handles theme changes through itsApplyCoremethod, but visual state setters that are already applied were not receiving theme change notifications.Solution
Modified the
OnParentResourcesChangedmethod inVisualElement.csto detect app theme changes and re-apply the current visual state. This ensures that all setters in the active visual state are re-evaluated with the new theme values.Key Changes
OnParentResourcesChanged()method to check forAppThemeBinding.AppThemeResourceReapplyCurrentVisualState()method that safely re-applies current states for all visual state groupsExample
Testing
The fix is minimal, efficient, and surgical - it only adds the necessary logic to handle theme changes without affecting other functionality.
Fixes #7.
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:
37cvsblobprodcus359.vsblob.vsassets.iodotnet build src/Controls/src/Core/Controls.Core.csproj -c Release --no-restore(dns block)4zjvsblobprodcus390.vsblob.vsassets.iodotnet build src/Controls/src/Core/Controls.Core.csproj -c Release --no-restore(dns block)7devsblobprodcus323.vsblob.vsassets.iodotnet build src/Controls/src/Core/Controls.Core.csproj -c Release --no-restore(dns block)l49vsblobprodcus358.vsblob.vsassets.iodotnet build src/Controls/src/Core/Controls.Core.csproj -c Release --no-restore(dns block)ljcvsblobprodcus317.vsblob.vsassets.iodotnet build src/Controls/src/Core/Controls.Core.csproj -c Release --no-restore(dns block)s8mvsblobprodcus38.vsblob.vsassets.iodotnet build src/Controls/src/Core/Controls.Core.csproj -c Release --no-restore(dns block)st8vsblobprodcus339.vsblob.vsassets.iodotnet build src/Controls/src/Core/Controls.Core.csproj -c Release --no-restore(dns block)ytvvsblobprodcus310.vsblob.vsassets.iodotnet build src/Controls/src/Core/Controls.Core.csproj -c Release --no-restore(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.