开关控制在默认情况下未打开时看起来变淡。

huangapple go评论64阅读模式
英文:

Switch control appears faded when not toggedon by default

问题

我在我的一个表单上有一堆数据绑定的开关:

<Label Grid.Column="0" Grid.Row="0" Text="选项 1" VerticalOptions="Center" FontSize="Large" HorizontalOptions="Start"/>
<Switch Grid.Column="1" Grid.Row="0" IsToggled="{Binding Options.One, Mode=TwoWay}" HorizontalOptions="End"/>
<Label Grid.Column="0" Grid.Row="1" Text="选项 2" VerticalOptions="Center" FontSize="Large" HorizontalOptions="Start"/>
<Switch Grid.Column="1" Grid.Row="1" IsToggled="{Binding Options.Two, Mode=TwoWay}" HorizontalOptions="End"/>
<Label Grid.Column="0" Grid.Row="2" Text="选项 3" VerticalOptions="Center" FontSize="Large" HorizontalOptions="Start"/>
<Switch Grid.Column="1" Grid.Row="2" IsToggled="{Binding Options.Three, Mode=TwoWay}" HorizontalOptions="End"/>
<Label Grid.Column="0" Grid.Row="3" Text="选项 4" VerticalOptions="Center" FontSize="Large" HorizontalOptions="Start"/>
<Switch Grid.Column="1" Grid.Row="3" IsToggled="{Binding Options.Four, Mode=TwoWay}" HorizontalOptions="End"/>
<Label Grid.Column="0" Grid.Row="4" Text="选项 5" VerticalOptions="Center" FontSize="Large" HorizontalOptions="Start"/>
<Switch Grid.Column="1" Grid.Row="4" IsToggled="{Binding Options.Five, Mode=TwoWay}"/>

功能上,这个工作得如预期。但是,我在UI方面看到了一些奇怪的现象...

如果绑定源在页面显示时提供了"true",那么开关控件看起来正如我所期望的那样 - 明亮而美观,无论你多少次切换它。

然而,如果绑定源提供了"false",然后你将开关切换到"on",那么它看起来会变得模糊 - 几乎像是被禁用了,尽管它是完全可用的。

正如我所说,这背后的功能是正常的 - 我的绑定属性被正确更新 - 只是视觉外观让我感到不适 :)

在这张图片中,所有奇数选项的绑定属性都设置为"true",而偶数选项的绑定属性都设置为"false"。
然后我切换了每个选项几次。

英文:

I've got a bunch of databound switches on one of my forms:

&lt;Label Grid.Column=&quot;0&quot; Grid.Row=&quot;0&quot; Text=&quot;option 1&quot; VerticalOptions=&quot;Center&quot; FontSize=&quot;Large&quot; HorizontalOptions=&quot;Start&quot;/&gt;
&lt;Switch Grid.Column=&quot;1&quot; Grid.Row=&quot;0&quot; IsToggled=&quot;{Binding Options.One, Mode=TwoWay}&quot; HorizontalOptions=&quot;End&quot;/&gt;
&lt;Label Grid.Column=&quot;0&quot; Grid.Row=&quot;1&quot; Text=&quot;option 2&quot; VerticalOptions=&quot;Center&quot; FontSize=&quot;Large&quot; HorizontalOptions=&quot;Start&quot;/&gt;
&lt;Switch Grid.Column=&quot;1&quot; Grid.Row=&quot;1&quot; IsToggled=&quot;{Binding Options.Two, Mode=TwoWay}&quot; HorizontalOptions=&quot;End&quot;/&gt;
&lt;Label Grid.Column=&quot;0&quot; Grid.Row=&quot;2&quot; Text=&quot;option 3&quot; VerticalOptions=&quot;Center&quot; FontSize=&quot;Large&quot; HorizontalOptions=&quot;Start&quot;/&gt;
&lt;Switch Grid.Column=&quot;1&quot; Grid.Row=&quot;2&quot; IsToggled=&quot;{Binding Options.Three, Mode=TwoWay}&quot; HorizontalOptions=&quot;End&quot;/&gt;
&lt;Label Grid.Column=&quot;0&quot; Grid.Row=&quot;3&quot; Text=&quot;option 4&quot; VerticalOptions=&quot;Center&quot; FontSize=&quot;Large&quot; HorizontalOptions=&quot;Start&quot;/&gt;
&lt;Switch Grid.Column=&quot;1&quot; Grid.Row=&quot;3&quot; IsToggled=&quot;{Binding Options.Four, Mode=TwoWay}&quot; HorizontalOptions=&quot;End&quot;/&gt;
&lt;Label Grid.Column=&quot;0&quot; Grid.Row=&quot;4&quot; Text=&quot;option 5&quot; VerticalOptions=&quot;Center&quot; FontSize=&quot;Large&quot; HorizontalOptions=&quot;Start&quot;/&gt;
&lt;Switch Grid.Column=&quot;1&quot; Grid.Row=&quot;4&quot; IsToggled=&quot;{Binding Options.Five, Mode=TwoWay}&quot;/&gt;

Functionally, this is working as expected. However, I'm seeing a bit of an oddity with the UI...

If the binding source provides "true" at the point the page is displayed, the switch control looks as I'd expect - nice and bright, no matter how many times I toggle it.

However, if the binding source provides "false", and you then toggle the switch to "on", then it looks faded - almost as if it's disabled, even though its fully usable.

As I say, the functionality behind this works - my bound properties are getting updated correctly - it's just the visual appearance that's bugging me 开关控制在默认情况下未打开时看起来变淡。

In this picture, all the bound properties for odd-numbered options was set to "true", whereas the bound properties for the even-numbered ones were set "false".
I've then toggled each option off and on a few times:
开关控制在默认情况下未打开时看起来变淡。

答案1

得分: 2

这是在XF 4.2.0中引入的bug。要解决它,您需要降级到低于4.2.0的版本,或者升级到Xamarin.Forms 4.4.0.991210-pre2(4.4.0预览版2)或更高版本,其中修复了bug

如果可能的话,我建议升级到XF 4.4.0稳定版。

英文:

This was a bug introduced in XF 4.2.0. To resolve it, you'll need to downgrade to something lower than 4.2.0 or upgrade to Xamarin.Forms 4.4.0.991210-pre2 (4.4.0 Pre Release 2) or higher where the bug was fixed.

If possible, my recommendation would be to upgrade to XF 4.4.0 stable.

huangapple
  • 本文由 发表于 2020年1月6日 21:25:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/59612963.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定