<Frame>
<Label Text="Hello Forms."></Label>
</Frame>
我使用框架来显示阴影,但在 U W P 项目的情况下它不会在跨平台显示
人们在 Github 中已经创建了一个关于这个问题的问题:UWP 帧没有阴影?
那里的回复说:
嗯,虽然边界更新是 引发 通过 HasShadow 属性,它似乎没有应用任何阴影。看起来 像这样从未实施过。
Xamarin 团队已注意到此问题,并将在将来处理它。
此外,还有一个示例项目使用 UWP 中的 DropDhadowPanel 在控件上获得阴影效果,您可以查看该线程并尝试一下。
UWP 中的自定义呈现器代码:
[assembly: ExportRenderer(typeof(ShadowLabel), typeof(ShadowLabelRenderer))]
namespace EffectsDemo.UWP
{
class ShadowLabelRenderer : ViewRenderer<ShadowLabel, DropShadowPanel>
{
protected override void OnElementChanged(ElementChangedEventArgs<ShadowLabel> e)
{
base.OnElementChanged(e);
if (Control == null)
{
// Instantiate the native control and assign it to the Control property with
// the SetNativeControl method
var effect = (ShadowEffect)Element.Effects.FirstOrDefault(x => x is ShadowEffect);
DropShadowPanel dsPanel = new DropShadowPanel();
dsPanel.Content = new TextBlock() { Text = Element.Text };
dsPanel.BlurRadius = effect.Radius;
Windows.UI.Color color = Windows.UI.Color.FromArgb(
Convert.ToByte(effect.Color.A * 255),
Convert.ToByte(effect.Color.R * 255),
Convert.ToByte(effect.Color.G * 255),
Convert.ToByte(effect.Color.B * 255));
dsPanel.Color = color;
dsPanel.OffsetX = effect.DistanceX;
dsPanel.OffsetY = effect.DistanceY;
SetNativeControl(dsPanel);
}
if (e.OldElement != null)
{
// Unsubscribe from event handlers and cleanup any resources
}
if (e.NewElement != null)
{
// Configure the control and subscribe to event handlers
}
}
}
}