Add Target to LinkView, LinkLabel, and Anchor

Fixes #60
This commit is contained in:
Frank A. Krueger 2018-02-01 22:52:39 -08:00
parent 8322ddaae3
commit db417111fd
5 changed files with 37 additions and 2 deletions

View File

@ -6,13 +6,21 @@ namespace Ooui.Forms
public class LinkLabel : Xamarin.Forms.Label public class LinkLabel : Xamarin.Forms.Label
{ {
public static readonly BindableProperty HRefProperty = BindableProperty.Create ("HRef", typeof (string), 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 { public string HRef {
get { return (string)base.GetValue (HRefProperty); } get { return (string)base.GetValue (HRefProperty); }
set { base.SetValue (HRefProperty, value); } 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 () public LinkLabel ()
{ {
} }

View File

@ -13,6 +13,14 @@ namespace Ooui.Forms
set { base.SetValue (HRefProperty, value); } 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 () public LinkView ()
{ {
} }

View File

@ -57,6 +57,7 @@ namespace Ooui.Forms.Renderers
} }
UpdateHRef (); UpdateHRef ();
UpdateTarget ();
UpdateText (); UpdateText ();
UpdateTextColor (); UpdateTextColor ();
@ -107,6 +108,11 @@ namespace Ooui.Forms.Renderers
Control.HRef = Element.HRef; Control.HRef = Element.HRef;
} }
void UpdateTarget ()
{
Control.Target = Element.HRef;
}
void UpdateAlignment () void UpdateAlignment ()
{ {
this.Style.Display = "table"; this.Style.Display = "table";

View File

@ -15,6 +15,7 @@ namespace Ooui.Forms.Renderers
base.OnElementChanged (e); base.OnElementChanged (e);
UpdateHRef (); UpdateHRef ();
UpdateTarget ();
} }
protected override void OnElementPropertyChanged (object sender, PropertyChangedEventArgs e) protected override void OnElementPropertyChanged (object sender, PropertyChangedEventArgs e)
@ -24,13 +25,20 @@ namespace Ooui.Forms.Renderers
if (Control == null) if (Control == null)
return; return;
if (e.PropertyName == Ooui.Forms.LinkLabel.HRefProperty.PropertyName) if (e.PropertyName == Ooui.Forms.LinkView.HRefProperty.PropertyName)
UpdateHRef (); UpdateHRef ();
if (e.PropertyName == Ooui.Forms.LinkView.TargetProperty.PropertyName)
UpdateTarget ();
} }
void UpdateHRef () void UpdateHRef ()
{ {
this.SetAttribute ("href", Element.HRef); this.SetAttribute ("href", Element.HRef);
} }
void UpdateTarget ()
{
this.SetAttribute ("target", Element.Target);
}
} }
} }

View File

@ -9,6 +9,11 @@ namespace Ooui
set => SetAttributeProperty ("href", value); set => SetAttributeProperty ("href", value);
} }
public string Target {
get => GetStringAttribute ("target", "");
set => SetAttributeProperty ("target", value);
}
public Anchor () public Anchor ()
: base ("a") : base ("a")
{ {