PressedBackgroundColor on Theme Change
I have frames styled throughout my app. Here is an example:
<Color x:Key="LightGrayOpaqueDarkTheme">#73757575</Color>
<Color x:Key="OpaqueBakgroundLightTheme">#69000000</Color>
<Style TargetType="{x:Type Frame}" x:Key="EnabledLargeFrame" BasedOn="{StaticResource EditableFrame}">
<Setter Property="xct:TouchEffect.PressedAnimationDuration" Value="250" />
<Setter Property="xct:TouchEffect.PressedScale" Value="1.1" />
<Setter Property="CornerRadius" Value="8" />
<Setter Property="xct:TouchEffect.PressedBackgroundColor" Value="AliceBlue" />
</Style>
<Style TargetType="{x:Type Frame}" x:Key="EditableFrame">
<Setter Property="BorderColor" Value="{AppThemeBinding Dark={StaticResource LightGrayOpaqueDarkTheme}, Light={StaticResource OpaqueBakgroundLightTheme}}" />
<Setter Property="CornerRadius" Value="5" />
<Setter Property="BackgroundColor"
Value="{AppThemeBinding Dark={StaticResource LightGrayOpaqueDarkTheme}, Light={StaticResource OpaqueBakgroundLightTheme}}" />
<Setter Property="Padding" Value="5" />
<Setter Property="HasShadow" Value="False"/>
</Style>
If I switch themes on the app, the xct:TouchEffect.PressedBackgroundColor prevents the theme from changing correctly for the frame background color correctly. If I remove the setter it works perfectly
Here is the code for setting the theme
public static class ThemeSetHelper
{
public static void SetTheme()
{
ThemeType currentTheme = (ThemeType)Preferences.Get(ApplicationSettingsIdentifiers.TheTheme, 0);
switch (currentTheme)
{
case ThemeType.Light:
Xamarin.Forms.Application.Current.UserAppTheme = Xamarin.Forms.OSAppTheme.Light;
break;
case ThemeType.Dark:
Xamarin.Forms.Application.Current.UserAppTheme = Xamarin.Forms.OSAppTheme.Dark;
break;
}
var e = DependencyService.Get<IEnvironment>();
if(App.Current.RequestedTheme == OSAppTheme.Dark)
{
e?.SetStatusBarColor(Color.Black, false);
}
else
{
e?.SetStatusBarColor(Color.DimGray, false);
}
}
}
Description
If I include the <Setter Property="xct:TouchEffect.PressedBackgroundColor" Value="AliceBlue" />
on the frame, I cannot switch between themes for background color on the frame.
Stack Trace
Link to Reproduction Sample
Steps to Reproduce
- Create a frame and style based on the code I have shown you above
- Create a theme change class per the code i gave you above
- Change the theme and notice the background color does not change correctly
Expected Behavior
I would expect the background colors to change correctly
Actual Behavior
Background colors are not changing correctly
Basic Information
xamarin forms; 5.0.0.2545 XCT: 2.05
seems to be an issue on all android and ios devices
below is the log output and it appears the color is unable to convert. Maybe because the background color on the frame is an opaque color? I removed the opaque background color and the error went away and all worked good. It just does not seem to work with an opaque color
This error below does not show up if I remove the <Setter Property="xct:TouchEffect.PressedBackgroundColor" Value="AliceBlue" />
[ViewRootImpl@6fde6b3[MainActivity]] ViewPostIme pointer 0
[GestureDetector] obtain mCurrentMotionEventRaw. action: 3 id: 876920184
[GestureDetector] obtain mCurrentDownEvent. id: 876920184 caller: crc643f46942d9dd1fff9.Platform_DefaultRenderer.n_onTouchEvent:-2 crc643f46942d9dd1fff9.Platform_DefaultRenderer.onTouchEvent:51 android.view.View.dispatchTouchEvent:15533
[GestureDetector] obtain mCurrentMotionEventRaw. action: 2 id: 736740082
[ViewRootImpl@6fde6b3[MainActivity]] Surface Surface(name=null)/@0xc5b4a4e drawing to bitmap w=1080, h=2640
[ViewRootImpl@6fde6b3[MainActivity]] Drawing: package:com.companyname.NightForceMobileApp, metrics=DisplayMetrics{density=3.0, width=1080, height=2402, scaledDensity=3.0, xdpi=428.625, ydpi=424.405}, compatibilityInfo={480dpi always-compat}
[ViewRootImpl@6fde6b3[MainActivity]] Surface Surface(name=null)/@0xc5b4a4e drawing to bitmap w=1080, h=2640
[ViewRootImpl@6fde6b3[MainActivity]] Drawing: package:com.companyname.NightForceMobileApp, metrics=DisplayMetrics{density=3.0, width=1080, height=2402, scaledDensity=3.0, xdpi=428.625, ydpi=424.405}, compatibilityInfo={480dpi always-compat}
[ViewRootImpl@6fde6b3[MainActivity]] Surface Surface(name=null)/@0xc5b4a4e drawing to bitmap w=1080, h=2640
[ViewRootImpl@6fde6b3[MainActivity]] Drawing: package:com.companyname.NightForceMobileApp, metrics=DisplayMetrics{density=3.0, width=1080, height=2402, scaledDensity=3.0, xdpi=428.625, ydpi=424.405}, compatibilityInfo={480dpi always-compat}
[ViewRootImpl@6fde6b3[MainActivity]] ViewPostIme pointer 1
[DecorView] notifyKeepScreenOnChanged: keepScreenOn=false
[DecorView] notifyKeepScreenOnChanged: keepScreenOn=false
[ViewRootImpl@6fde6b3[MainActivity]] performTraversals params={(0,0)(fillxfill) sim={adjust=pan} layoutInDisplayCutoutMode=shortEdges ty=BASE_APPLICATION wanim=0x1030309
[ViewRootImpl@6fde6b3[MainActivity]] fl=80810100
[ViewRootImpl@6fde6b3[MainActivity]] pfl=12020040
[ViewRootImpl@6fde6b3[MainActivity]] bhv=DEFAULT
[ViewRootImpl@6fde6b3[MainActivity]] fitSides= naviIconColor=0}
[ViewRootImpl@6fde6b3[MainActivity]] performTraversals mFirst=false windowShouldResize=false viewVisibilityChanged=false mForceNextWindowRelayout=false params={(0,0)(fillxfill) sim={adjust=pan} layoutInDisplayCutoutMode=shortEdges ty=BASE_APPLICATION wanim=0x1030309
[ViewRootImpl@6fde6b3[MainActivity]] fl=80810100
[ViewRootImpl@6fde6b3[MainActivity]] pfl=12020040
[ViewRootImpl@6fde6b3[MainActivity]] bhv=DEFAULT
[ViewRootImpl@6fde6b3[MainActivity]] fitSides= naviIconColor=0}
[BLASTBufferQueue] update, w= 1080 h= 2640 mName = ViewRootImpl@6fde6b3[MainActivity] mNativeObject= 0x734298ca30 sc.mNativeObject= 0x72d29360e0 format= -1 caller= android.view.ViewRootImpl.updateBlastSurfaceIfNeeded:2804 android.view.ViewRootImpl.relayoutWindow:9661 android.view.ViewRootImpl.performTraversals:3785 android.view.ViewRootImpl.doTraversal:3017 android.view.ViewRootImpl$TraversalRunnable.run:10699 android.view.Choreographer$CallbackRecord.run:1301
[ViewRootImpl@6fde6b3[MainActivity]] Relayout returned: old=(0,0,1080,2640) new=(0,0,1080,2640) req=(1080,2640)0 dur=4 res=0x0 s={true 0x73d54b2f40} ch=false seqId=0
[ViewRootImpl@6fde6b3[MainActivity]] Surface Surface(name=null)/@0xc5b4a4e drawing to bitmap w=1080, h=2640
[ViewRootImpl@6fde6b3[MainActivity]] Drawing: package:com.companyname.NightForceMobileApp, metrics=DisplayMetrics{density=3.0, width=1080, height=2402, scaledDensity=3.0, xdpi=428.625, ydpi=424.405}, compatibilityInfo={480dpi always-compat}
[DecorView] setWindowBackground: isPopOver=false color=fff6f6f6 d=crc643f46942d9dd1fff9.ShellRenderer_SplitDrawable@8735d79
[DecorView] notifyKeepScreenOnChanged: keepScreenOn=false
[0:] SetValue: Cannot convert to type 'Xamarin.Forms.Color'
[0:] SetValue: Cannot convert to type 'Xamarin.Forms.Color'
[0:] SetValue: Cannot convert to type 'Xamarin.Forms.Color'
[0:] SetValue: Cannot convert to type 'Xamarin.Forms.Color'
[0:] SetValue: Cannot convert to type 'Xamarin.Forms.Color'
[0:] SetValue: Cannot convert to type 'Xamarin.Forms.Color'
[0:] SetValue: Cannot convert to type 'Xamarin.Forms.Color'
[0:] SetValue: Cannot convert to type 'Xamarin.Forms.Color'
[0:] SetValue: Cannot convert to type 'Xamarin.Forms.Color'
[0:] SetValue: Cannot convert to type 'Xamarin.Forms.Color'
Workaround
Reproduction imagery
Any workaround?
@Mercally not that I have found. I removed the issues form the problem from the style and put them on the control...and then it works. Not sure why in the style it will not.