<Frame>
<Label Text="Hello Forms."></Label>
</Frame>
我使用框架来显示阴影,但在 U W P 项目的情况下,它无法在跨平台中显示
最佳答案
人们已经在 Github 上创建了一个关于此问题的问题:No shadows for UWP Frames?
那里的回复说:
Hm although the border update is triggered by the HasShadow property, it doesn't seem to apply any shadow. Looks like this never was implemented.
Xamarin 团队已注意到此问题,并将在未来解决该问题。
此外,还有一个示例项目 use the DropDhadowPanel在 UWP 中获得控件上的阴影效果。您可以查看该线程并尝试一下。
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
}
}
}
}
关于android - 在 IOS 中使用框架阴影效果显示,但在 xamarin 中的 UWP 项目中则不使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59755231/