Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Overriding ContentPage and Setting Content outside the main constructor does not render

$
0
0

I am trying to build a Base Page... Essentially I would like to add a side bar to all pages of my application without having to add it to every pages Xaml (I don't want to use master detail as i would like my own custom implementation).

I am trying to Inherit from ContentPage and have my own HelpContentPage

In my HelpContentPage I have a Bindable property called PageContent such that my Xaml looks like this:

<custom:HelpContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:custom="clr-namespace:HelpBarExample.Custom;assembly=HelpBarExample"
             x:Class="HelpBarExample.MainPage">
  <custom:HelpContentPage.PageContent>
  <ScrollView>
    <StackLayout>
      <Button Text="Button 1" HorizontalOptions="FillAndExpand"/>
      <Button Text="Button 2" HorizontalOptions="FillAndExpand"/>
      <Button Text="Button 3" HorizontalOptions="FillAndExpand"/>
      <Button Text="Button 4" HorizontalOptions="FillAndExpand"/>
      <Button Text="Button 5" HorizontalOptions="FillAndExpand"/>
      <Button Text="Button 6" HorizontalOptions="FillAndExpand"/>
      <Button Text="Button 7" HorizontalOptions="FillAndExpand"/>
    </StackLayout>
  </ScrollView>
  </custom:HelpContentPage.PageContent>
</custom:HelpContentPage>

Now In my HelpContentPage when this property is set I basically try to set the Content of my page

  public View PageContent
        {
            get { return (View)this.GetValue(PageContentProperty); }
            set 
            { 
                this.SetValue(PageContentProperty, value);
                Device.BeginInvokeOnMainThread(() =>
                {
                    _layout.Children.Add(this.PageContent,
                        Constraint.RelativeToParent((p) =>
                        {
                            return 0;
                        }),
                        Constraint.RelativeToParent((p) =>
                        {
                            return Device.OnPlatform<int>(28, 0, 0);
                        }),
                        Constraint.RelativeToParent((p) =>
                        {
                            return 0;
                        }));

                    Mask = new BoxView();
                    Mask.VerticalOptions = LayoutOptions.FillAndExpand;
                    Mask.HorizontalOptions = LayoutOptions.FillAndExpand;
                    Mask.Opacity = 0;
                    Mask.BackgroundColor = Color.FromHex("#404040");
                    Mask.Color = Color.FromHex("#404040");
                    Mask.InputTransparent = true;

                    _layout.Children.Add(Mask,
                    Constraint.RelativeToParent((p) =>
                    {
                        return 0;
                    }),
                    Constraint.RelativeToParent((p) =>
                    {
                        return Device.OnPlatform<int>(28, 0, 0);
                    }),
                    Constraint.RelativeToParent((p) =>
                    {
                        return p.Width;
                        //return p.Width - (p.Width / 2.5);
                    }),
                    Constraint.RelativeToParent((p) =>
                    {
                        return p.Height;
                    }));

                    CreatePanel();

                    ContentDrawn = true;
                    this.Content = _layout;
                    this.ForceLayout();
                });
            }
        }

BUT setting Content and ForceLayout does not actually render the content of the page. I can see my side bar perfectly but my buttons in my ScrollView are nowhere to be seen.

Am I doing this right? How do I override ContentPage to achieve this? Is this a bug I need to report to Bugzilla?

Git Repository: https://github.com/JKennedy24/XamarinHelpBarExample/


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>