问题描述
我为框架元素制作了一个自定义渲染阴影 - 一切都很好,阴影适合我,但由于使用了这个自定义渲染,我对 RadioButton 元素产生了不好的影响,我该如何编辑这个渲染那个单选按钮元素是正常的? sample image
/// <summary>
/// Renderer to update all frames with better shadows matching material design standards
/// </summary>
public class MaterialFrameRenderer : FrameRenderer
{
public override void Draw(CGRect rect)
{
base.Draw(rect);
// Update shadow to match better material design standards of elevation
Layer.ShadowRadius = Element.CornerRadius;
Layer.ShadowColor = UIColor.Gray.CGColor;
Layer.ShadowOffset = new CGSize(2,2);
Layer.ShadowOpacity = 0.40f;
Layer.ShadowPath = UIBezierPath.Fromrect(Layer.Bounds).CGPath;
Layer.MasksToBounds = false;
}
}
解决方法
RadioButton Rendering 似乎有问题,我们甚至无法在 iOS 上为 RadioButton 创建自定义渲染器,请检查 https://forums.xamarin.com/discussion/comment/430069#Comment_430069。
我强烈建议您使用 Xamarin.Forms.InputKit 而不是 Xamarin RadioButton 。
还不错。
xmlns:input="clr-namespace:Plugin.InputKit.Shared.Controls;assembly=Plugin.InputKit"
<Frame Margin="100" CornerRadius="20" >
<input:RadioButtonGroupView>
<input:RadioButton Text="Option 1" />
<input:RadioButton Text="Option 2" />
<input:RadioButton Text="Option 3" />
<input:RadioButton Text="Option 4" />
</input:RadioButtonGroupView>
</Frame>
</ContentPage.Content>