Step1:ShadowEffect.cs
Step2:HomePage
Step3:Android Renderer
Step4:IOS Renderer
Step5:Holaa!!! No More Steps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ShadowEffect : RoutingEffect | |
{ | |
public float Radius { get; set; } | |
public Color Color { get; set; } | |
public float DistanceX { get; set; } | |
public float DistanceY { get; set; } | |
public ShadowEffect () : base ("MyCompany.LabelShadowEffect") | |
{ | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Grid Padding="0,20,0,0"> | |
<Label Text="Introducing New Black BMW" FontAttributes="Bold" | |
HorizontalOptions="CenterAndExpand" VerticalOptions="StartAndExpand" FontSize="Large"> | |
<Label.Effects> | |
<local:ShadowEffect Radius="5" DistanceX="5" DistanceY="5"> | |
<local:ShadowEffect.Color> | |
<OnPlatform x:TypeArguments="Color"> | |
<On Platform="iOS" Value="Black" /> | |
<On Platform="Android" Value="White" /> | |
<On Platform="UWP" Value="Red" /> | |
</OnPlatform> | |
</local:ShadowEffect.Color> | |
</local:ShadowEffect> | |
</Label.Effects> | |
</Label> | |
</Grid> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[assembly:ResolutionGroupName ("MyCompany")] | |
[assembly:ExportEffect (typeof(LabelShadowEffect), "LabelShadowEffect")] | |
namespace EffectsDemo.Droid | |
{ | |
public class LabelShadowEffect : PlatformEffect | |
{ | |
protected override void OnAttached () | |
{ | |
try { | |
var control = Control as Android.Widget.TextView; | |
var effect = (ShadowEffect)Element.Effects.FirstOrDefault (e => e is ShadowEffect); | |
if (effect != null) { | |
float radius = effect.Radius; | |
float distanceX = effect.DistanceX; | |
float distanceY = effect.DistanceY; | |
Android.Graphics.Color color = effect.Color.ToAndroid (); | |
control.SetShadowLayer (radius, distanceX, distanceY, color); | |
} | |
} catch (Exception ex) { | |
Console.WriteLine ("Cannot set property on attached control. Error: ", ex.Message); | |
} | |
} | |
protected override void OnDetached () | |
{ | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[assembly:ResolutionGroupName ("MyCompany")] | |
[assembly:ExportEffect (typeof(LabelShadowEffect), "LabelShadowEffect")] | |
namespace EffectsDemo.iOS | |
{ | |
public class LabelShadowEffect : PlatformEffect | |
{ | |
protected override void OnAttached () | |
{ | |
try { | |
var effect = (ShadowEffect)Element.Effects.FirstOrDefault (e => e is ShadowEffect); | |
if (effect != null) { | |
Control.Layer.CornerRadius = effect.Radius; | |
Control.Layer.ShadowColor = effect.Color.ToCGColor (); | |
Control.Layer.ShadowOffset = new CGSize (effect.DistanceX, effect.DistanceY); | |
Control.Layer.ShadowOpacity = 1.0f; | |
} | |
} catch (Exception ex) { | |
Console.WriteLine ("Cannot set property on attached control. Error: ", ex.Message); | |
} | |
} | |
protected override void OnDetached () | |
{ | |
} | |
} | |
} |
No comments:
Post a Comment