Create ContentPage template with fixed view on top












1














Our Xamarin.Forms app works online and offline by downloading an original database to the cell phone and then syncing the SQLite database with the online database.
Our users need a way to see if they are online and if the changes they made got uploaded to the online database. What I try to achieve is to show the sync status at the top of every ContentPage, so the users can see this information all the time while working with the app.



What I tried is this: create a class "SyncInfoContentPage" that inherits from ContentPage. All ContentPages I already wrote will now not inherit from ContentPage anymore but from SyncInfoContentPage.
The SyncInfoContentPage automatically takes its Content and replaces it with a new Stacklayout that includes the SyncInfo and the original content. By doing this I don't have to rewrite the 77 ContentPages we already have.



This code works fine on Android, but on iOS the SyncInfo is not visible and (even worse) my ContentPages that inherit from SyncInfoContentPage do not react to anything anymore.



Here is my code:



public class SyncInfoContentPage : ContentPage
{
private readonly Frame SyncInfo;

public SyncInfoContentPage()
{
SyncInfo = BuildSyncInfo(); //Creates the frame with the sync Information
PropertyChanged += SyncInfoContentPage_PropertyChanged;
}

private void SyncInfoContentPage_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
// Add the SyncInfo Frame on top of the Content when the Content gets changed
if (e.PropertyName.Equals("Content"))
{
bool change = false;
// If the content already is a StackLayout, check if the SyncInfo already got added, so that theres no infinite loop.
if (Content is StackLayout)
{
var check = Content as StackLayout;
if (!check.Children.Contains(SyncInfo))
{
change = true;
}
}
else // if the Content is no StackLayout, the SyncInfo Frame can't be inside the Content yet
{
change = true;
}

if (change)
{
var layout = Content; // This is a reference, probably the error?
Device.BeginInvokeOnMainThread(() =>
{
Content = new StackLayout
{
Children = { SyncInfo, layout }
};
});
}
}
}
}


The problem is probably that iOS doesn't like this part:



var layout = Content;
Content = new StackLayout { Children = { SyncInfo, layout } };


Thanks in advance for your help and any suggestions :-)










share|improve this question



























    1














    Our Xamarin.Forms app works online and offline by downloading an original database to the cell phone and then syncing the SQLite database with the online database.
    Our users need a way to see if they are online and if the changes they made got uploaded to the online database. What I try to achieve is to show the sync status at the top of every ContentPage, so the users can see this information all the time while working with the app.



    What I tried is this: create a class "SyncInfoContentPage" that inherits from ContentPage. All ContentPages I already wrote will now not inherit from ContentPage anymore but from SyncInfoContentPage.
    The SyncInfoContentPage automatically takes its Content and replaces it with a new Stacklayout that includes the SyncInfo and the original content. By doing this I don't have to rewrite the 77 ContentPages we already have.



    This code works fine on Android, but on iOS the SyncInfo is not visible and (even worse) my ContentPages that inherit from SyncInfoContentPage do not react to anything anymore.



    Here is my code:



    public class SyncInfoContentPage : ContentPage
    {
    private readonly Frame SyncInfo;

    public SyncInfoContentPage()
    {
    SyncInfo = BuildSyncInfo(); //Creates the frame with the sync Information
    PropertyChanged += SyncInfoContentPage_PropertyChanged;
    }

    private void SyncInfoContentPage_PropertyChanged(object sender, PropertyChangedEventArgs e)
    {
    // Add the SyncInfo Frame on top of the Content when the Content gets changed
    if (e.PropertyName.Equals("Content"))
    {
    bool change = false;
    // If the content already is a StackLayout, check if the SyncInfo already got added, so that theres no infinite loop.
    if (Content is StackLayout)
    {
    var check = Content as StackLayout;
    if (!check.Children.Contains(SyncInfo))
    {
    change = true;
    }
    }
    else // if the Content is no StackLayout, the SyncInfo Frame can't be inside the Content yet
    {
    change = true;
    }

    if (change)
    {
    var layout = Content; // This is a reference, probably the error?
    Device.BeginInvokeOnMainThread(() =>
    {
    Content = new StackLayout
    {
    Children = { SyncInfo, layout }
    };
    });
    }
    }
    }
    }


    The problem is probably that iOS doesn't like this part:



    var layout = Content;
    Content = new StackLayout { Children = { SyncInfo, layout } };


    Thanks in advance for your help and any suggestions :-)










    share|improve this question

























      1












      1








      1







      Our Xamarin.Forms app works online and offline by downloading an original database to the cell phone and then syncing the SQLite database with the online database.
      Our users need a way to see if they are online and if the changes they made got uploaded to the online database. What I try to achieve is to show the sync status at the top of every ContentPage, so the users can see this information all the time while working with the app.



      What I tried is this: create a class "SyncInfoContentPage" that inherits from ContentPage. All ContentPages I already wrote will now not inherit from ContentPage anymore but from SyncInfoContentPage.
      The SyncInfoContentPage automatically takes its Content and replaces it with a new Stacklayout that includes the SyncInfo and the original content. By doing this I don't have to rewrite the 77 ContentPages we already have.



      This code works fine on Android, but on iOS the SyncInfo is not visible and (even worse) my ContentPages that inherit from SyncInfoContentPage do not react to anything anymore.



      Here is my code:



      public class SyncInfoContentPage : ContentPage
      {
      private readonly Frame SyncInfo;

      public SyncInfoContentPage()
      {
      SyncInfo = BuildSyncInfo(); //Creates the frame with the sync Information
      PropertyChanged += SyncInfoContentPage_PropertyChanged;
      }

      private void SyncInfoContentPage_PropertyChanged(object sender, PropertyChangedEventArgs e)
      {
      // Add the SyncInfo Frame on top of the Content when the Content gets changed
      if (e.PropertyName.Equals("Content"))
      {
      bool change = false;
      // If the content already is a StackLayout, check if the SyncInfo already got added, so that theres no infinite loop.
      if (Content is StackLayout)
      {
      var check = Content as StackLayout;
      if (!check.Children.Contains(SyncInfo))
      {
      change = true;
      }
      }
      else // if the Content is no StackLayout, the SyncInfo Frame can't be inside the Content yet
      {
      change = true;
      }

      if (change)
      {
      var layout = Content; // This is a reference, probably the error?
      Device.BeginInvokeOnMainThread(() =>
      {
      Content = new StackLayout
      {
      Children = { SyncInfo, layout }
      };
      });
      }
      }
      }
      }


      The problem is probably that iOS doesn't like this part:



      var layout = Content;
      Content = new StackLayout { Children = { SyncInfo, layout } };


      Thanks in advance for your help and any suggestions :-)










      share|improve this question













      Our Xamarin.Forms app works online and offline by downloading an original database to the cell phone and then syncing the SQLite database with the online database.
      Our users need a way to see if they are online and if the changes they made got uploaded to the online database. What I try to achieve is to show the sync status at the top of every ContentPage, so the users can see this information all the time while working with the app.



      What I tried is this: create a class "SyncInfoContentPage" that inherits from ContentPage. All ContentPages I already wrote will now not inherit from ContentPage anymore but from SyncInfoContentPage.
      The SyncInfoContentPage automatically takes its Content and replaces it with a new Stacklayout that includes the SyncInfo and the original content. By doing this I don't have to rewrite the 77 ContentPages we already have.



      This code works fine on Android, but on iOS the SyncInfo is not visible and (even worse) my ContentPages that inherit from SyncInfoContentPage do not react to anything anymore.



      Here is my code:



      public class SyncInfoContentPage : ContentPage
      {
      private readonly Frame SyncInfo;

      public SyncInfoContentPage()
      {
      SyncInfo = BuildSyncInfo(); //Creates the frame with the sync Information
      PropertyChanged += SyncInfoContentPage_PropertyChanged;
      }

      private void SyncInfoContentPage_PropertyChanged(object sender, PropertyChangedEventArgs e)
      {
      // Add the SyncInfo Frame on top of the Content when the Content gets changed
      if (e.PropertyName.Equals("Content"))
      {
      bool change = false;
      // If the content already is a StackLayout, check if the SyncInfo already got added, so that theres no infinite loop.
      if (Content is StackLayout)
      {
      var check = Content as StackLayout;
      if (!check.Children.Contains(SyncInfo))
      {
      change = true;
      }
      }
      else // if the Content is no StackLayout, the SyncInfo Frame can't be inside the Content yet
      {
      change = true;
      }

      if (change)
      {
      var layout = Content; // This is a reference, probably the error?
      Device.BeginInvokeOnMainThread(() =>
      {
      Content = new StackLayout
      {
      Children = { SyncInfo, layout }
      };
      });
      }
      }
      }
      }


      The problem is probably that iOS doesn't like this part:



      var layout = Content;
      Content = new StackLayout { Children = { SyncInfo, layout } };


      Thanks in advance for your help and any suggestions :-)







      xamarin xamarin.forms xamarin.ios






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 14 '18 at 16:00









      Tobe

      69110




      69110
























          1 Answer
          1






          active

          oldest

          votes


















          0














          I got it to work. The solution is simple but strange. You have to add the original Content after you added the SyncInfo status bar.



                              var layoutOld = Content; 
          var layoutNew = new StackLayout
          {
          Children = { SyncInfo }
          };
          Content = layoutNew;
          layoutNeu.Children.Add(layoutOld);





          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53304241%2fcreate-contentpage-template-with-fixed-view-on-top%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            I got it to work. The solution is simple but strange. You have to add the original Content after you added the SyncInfo status bar.



                                var layoutOld = Content; 
            var layoutNew = new StackLayout
            {
            Children = { SyncInfo }
            };
            Content = layoutNew;
            layoutNeu.Children.Add(layoutOld);





            share|improve this answer


























              0














              I got it to work. The solution is simple but strange. You have to add the original Content after you added the SyncInfo status bar.



                                  var layoutOld = Content; 
              var layoutNew = new StackLayout
              {
              Children = { SyncInfo }
              };
              Content = layoutNew;
              layoutNeu.Children.Add(layoutOld);





              share|improve this answer
























                0












                0








                0






                I got it to work. The solution is simple but strange. You have to add the original Content after you added the SyncInfo status bar.



                                    var layoutOld = Content; 
                var layoutNew = new StackLayout
                {
                Children = { SyncInfo }
                };
                Content = layoutNew;
                layoutNeu.Children.Add(layoutOld);





                share|improve this answer












                I got it to work. The solution is simple but strange. You have to add the original Content after you added the SyncInfo status bar.



                                    var layoutOld = Content; 
                var layoutNew = new StackLayout
                {
                Children = { SyncInfo }
                };
                Content = layoutNew;
                layoutNeu.Children.Add(layoutOld);






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 15 '18 at 9:02









                Tobe

                69110




                69110






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53304241%2fcreate-contentpage-template-with-fixed-view-on-top%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    How to pass form data using jquery Ajax to insert data in database?

                    National Museum of Racing and Hall of Fame

                    Guess what letter conforming each word