android - 在 IOS 中使用框架阴影效果显示,但在 xamarin 中的 UWP 项目中则不使用

标签 android ios asp.net windows uwp

<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/

相关文章:

android - 尽管已被销毁,但多次打开子 Activity 会导致 InstanceCountViolation

java - 非法状态异常 : Task is not yet complete: adding data from Firebase to a pin in google maps Android Studio

android - 使用 resValue 从 build.gradle 生成包含 % 的字符串资源

asp.net - ASP.Net 面板的水印

javascript - 在 ASP.NET 中从 cookie 中获取日期

android - 多窗口不工作

objective-c - UITableView 数据源问题。当 UITableView :cellForRowAtIndexPath: is called 时,我的数据数组突然为空

ios - 类型 'AppDelegate' 的值没有成员 'manageObjectContext'

objective-c - 对象保持到应用程序结束 : No Dealloc is okay?

javascript - JS函数不在表单内部调用