From db417111fd2562067fe0a6669bd57574d0687392 Mon Sep 17 00:00:00 2001 From: "Frank A. Krueger" Date: Thu, 1 Feb 2018 22:52:39 -0800 Subject: [PATCH] Add Target to LinkView, LinkLabel, and Anchor Fixes #60 --- Ooui.Forms/Controls/LinkLabel.cs | 10 +++++++++- Ooui.Forms/Controls/LinkView.cs | 8 ++++++++ Ooui.Forms/Renderers/LinkLabelRenderer.cs | 6 ++++++ Ooui.Forms/Renderers/LinkViewRenderer.cs | 10 +++++++++- Ooui/Anchor.cs | 5 +++++ 5 files changed, 37 insertions(+), 2 deletions(-) diff --git a/Ooui.Forms/Controls/LinkLabel.cs b/Ooui.Forms/Controls/LinkLabel.cs index 5371101..de8384c 100644 --- a/Ooui.Forms/Controls/LinkLabel.cs +++ b/Ooui.Forms/Controls/LinkLabel.cs @@ -6,13 +6,21 @@ namespace Ooui.Forms public class LinkLabel : Xamarin.Forms.Label { public static readonly BindableProperty HRefProperty = BindableProperty.Create ("HRef", typeof (string), - typeof (LinkView), string.Empty, BindingMode.OneWay, null, null, null, null); + typeof (LinkLabel), string.Empty, BindingMode.OneWay, null, null, null, null); public string HRef { get { return (string)base.GetValue (HRefProperty); } set { base.SetValue (HRefProperty, value); } } + public static readonly BindableProperty TargetProperty = BindableProperty.Create ("Target", typeof (string), + typeof (LinkLabel), string.Empty, BindingMode.OneWay, null, null, null, null); + + public string Target { + get { return (string)base.GetValue (TargetProperty); } + set { base.SetValue (TargetProperty, value); } + } + public LinkLabel () { } diff --git a/Ooui.Forms/Controls/LinkView.cs b/Ooui.Forms/Controls/LinkView.cs index fd51d53..b372723 100644 --- a/Ooui.Forms/Controls/LinkView.cs +++ b/Ooui.Forms/Controls/LinkView.cs @@ -13,6 +13,14 @@ namespace Ooui.Forms set { base.SetValue (HRefProperty, value); } } + public static readonly BindableProperty TargetProperty = BindableProperty.Create ("Target", typeof (string), + typeof (LinkView), string.Empty, BindingMode.OneWay, null, null, null, null); + + public string Target { + get { return (string)base.GetValue (TargetProperty); } + set { base.SetValue (TargetProperty, value); } + } + public LinkView () { } diff --git a/Ooui.Forms/Renderers/LinkLabelRenderer.cs b/Ooui.Forms/Renderers/LinkLabelRenderer.cs index 3d7fe61..baece02 100644 --- a/Ooui.Forms/Renderers/LinkLabelRenderer.cs +++ b/Ooui.Forms/Renderers/LinkLabelRenderer.cs @@ -57,6 +57,7 @@ namespace Ooui.Forms.Renderers } UpdateHRef (); + UpdateTarget (); UpdateText (); UpdateTextColor (); @@ -107,6 +108,11 @@ namespace Ooui.Forms.Renderers Control.HRef = Element.HRef; } + void UpdateTarget () + { + Control.Target = Element.HRef; + } + void UpdateAlignment () { this.Style.Display = "table"; diff --git a/Ooui.Forms/Renderers/LinkViewRenderer.cs b/Ooui.Forms/Renderers/LinkViewRenderer.cs index 4ee222b..e2ceb2a 100644 --- a/Ooui.Forms/Renderers/LinkViewRenderer.cs +++ b/Ooui.Forms/Renderers/LinkViewRenderer.cs @@ -15,6 +15,7 @@ namespace Ooui.Forms.Renderers base.OnElementChanged (e); UpdateHRef (); + UpdateTarget (); } protected override void OnElementPropertyChanged (object sender, PropertyChangedEventArgs e) @@ -24,13 +25,20 @@ namespace Ooui.Forms.Renderers if (Control == null) return; - if (e.PropertyName == Ooui.Forms.LinkLabel.HRefProperty.PropertyName) + if (e.PropertyName == Ooui.Forms.LinkView.HRefProperty.PropertyName) UpdateHRef (); + if (e.PropertyName == Ooui.Forms.LinkView.TargetProperty.PropertyName) + UpdateTarget (); } void UpdateHRef () { this.SetAttribute ("href", Element.HRef); } + + void UpdateTarget () + { + this.SetAttribute ("target", Element.Target); + } } } diff --git a/Ooui/Anchor.cs b/Ooui/Anchor.cs index 6ea2853..a475fca 100644 --- a/Ooui/Anchor.cs +++ b/Ooui/Anchor.cs @@ -9,6 +9,11 @@ namespace Ooui set => SetAttributeProperty ("href", value); } + public string Target { + get => GetStringAttribute ("target", ""); + set => SetAttributeProperty ("target", value); + } + public Anchor () : base ("a") {