How can I use Xamarin.Forms.Platform.UWP.TabbedPageRenderer ? No method to override!

PhilipOGormanPhilipOGorman USMember ✭✭✭

I am trying to create a renderer for a tabbed page. When I look at TabbedPageRenderer, there is nothing to override :

`namespace Xamarin.Forms.Platform.UWP
{
public class TabbedPageRenderer : IVisualElementRenderer, IRegisterable, IDisposable, ITitleProvider
{
public TabbedPageRenderer();

    public FrameworkElement ContainerElement { get; }
    public Pivot Control { get; }
    public TabbedPage Element { get; }
    protected VisualElementTracker<Page, Pivot> Tracker { get; set; }

    public event EventHandler<VisualElementChangedEventArgs> ElementChanged;

    public void Dispose();
    public SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint);
    public void SetElement(VisualElement element);
    protected virtual void Dispose(bool disposing);
    protected void OnElementChanged(VisualElementChangedEventArgs e);
}

}`

The usual method gives an error:
public class CustomTabRenderer : TabbedPageRenderer { protected override void OnElementChanged(VisualElementChangedEventArgs e) { base.OnElementChanged(e); } }

what can I do here?

Best Answer

Answers

  • PhilipOGormanPhilipOGorman USMember ✭✭✭

    with a liitle help from here https://nocture.dk/2014/12/10/xamarin-forms-customizing-tabbed-page-header-title-windows-phone/

    I got it to work:

    ` public class CustomTabRenderer : TabbedPageRenderer
    {
    public CustomTabRenderer()
    {
    this.ElementChanged += CustomTabRenderer_ElementChanged;

        }
    
        private void CustomTabRenderer_ElementChanged(object sender, VisualElementChangedEventArgs e)
        {
            Control.HeaderTemplate = GetStyledTitleTemplate();
        }
    
        private Windows.UI.Xaml.DataTemplate GetStyledTitleTemplate()
        {
            string dataTemplateXaml = @"<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
                xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
                    <TextBlock
                        Text=""{Binding}""
                        FontFamily=""Segoe UI""
                        FontWeight=""Light""
                        Foreground=""Red""
                        FontSize=""90"" />
                      </DataTemplate>";
    
            return (Windows.UI.Xaml.DataTemplate)XamlReader.Load(dataTemplateXaml);
        }
    }`
    
  • When I use this, there is a Parsing Exception in XamlReader.Load(dataTemplateXaml)

Sign In or Register to comment.