diff options
Diffstat (limited to 'Xamarin.Forms.Platform.Tizen/Renderers/ContentPageRenderer.cs')
-rw-r--r-- | Xamarin.Forms.Platform.Tizen/Renderers/ContentPageRenderer.cs | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.Tizen/Renderers/ContentPageRenderer.cs b/Xamarin.Forms.Platform.Tizen/Renderers/ContentPageRenderer.cs new file mode 100644 index 00000000..c4f79653 --- /dev/null +++ b/Xamarin.Forms.Platform.Tizen/Renderers/ContentPageRenderer.cs @@ -0,0 +1,65 @@ +using System; +using EColor = ElmSharp.Color; + +namespace Xamarin.Forms.Platform.Tizen +{ + /// <summary> + /// Renderer of ContentPage. + /// </summary> + public class ContentPageRenderer : VisualElementRenderer<ContentPage> + { + /// <summary> + /// Native control which holds the contents. + /// </summary> + Native.ContentPage _page; + + /// <summary> + /// Default constructor. + /// </summary> + public ContentPageRenderer() + { + RegisterPropertyHandler(Page.BackgroundImageProperty, UpdateBackgroundImage); + RegisterPropertyHandler(Page.TitleProperty, UpdateTitle); + } + + protected override void OnElementChanged(ElementChangedEventArgs<ContentPage> e) + { + if (null == _page) + { + _page = new Native.ContentPage(Forms.Context.MainWindow); + _page.LayoutUpdated += new EventHandler<Native.LayoutEventArgs>(OnLayoutUpdated); + SetNativeControl(_page); + } + + base.OnElementChanged(e); + } + + protected override void UpdateBackgroundColor() + { + // base.UpdateBackgroundColor() is not called on purpose, we don't want the regular background setting + if (Element.BackgroundColor.IsDefault || Element.BackgroundColor.A == 0) + _page.Color = EColor.Transparent; + else + _page.Color = Element.BackgroundColor.ToNative(); + } + + void UpdateBackgroundImage() + { + if (string.IsNullOrWhiteSpace(Element.BackgroundImage)) + _page.File = null; + else + _page.File = ResourcePath.GetPath(Element.BackgroundImage); + } + + void UpdateTitle() + { + _page.Title = Element.Title; + } + + void OnLayoutUpdated(object sender, Native.LayoutEventArgs e) + { + DoLayout(e); + } + } +} + |