Xamarin Forms Grid conditional RowSpan












0














I have a generic Grid List Control. Which let me Bind the Item Source and ItemTemplate and it will generates the Column and Rows based on Number of Items or Based on how Users set the Rows and Columns. Its perfect until here. It supports all the generics I needed.



Now the Problem part:
I have a ContentView which will be used as Item Template for the Grid. This Template will be used for Multiple Data Types. I'm able to do it properly. Now I have one Data Type Where the First Cell should have RowSpan if it meets certain condition: The code below works perfect. It creates the RowSpan perfectly.



    bool isYearBuilt = false;
bool isAny = false;

public FilterItemView()
{
InitializeComponent();
}

protected override void OnBindingContextChanged()
{
base.OnBindingContextChanged();

var context = BindingContext as PropertyFilterItem;
if (context == null)
return;

if(context.FilterType==PropertyFilterTypes.YearBuilt)
{
if(context.IsAny)
{
isYearBuilt = true; isAny = true;
}
}
}


protected override void OnParentSet()
{
base.OnParentSet();
GridList grid = this.Parent as GridList;
if (grid == null)
return;

if(isYearBuilt && isAny)
{
Grid.SetRowSpan(this, 2);
}
}


These are the Images; which will describe it more perfectly:
This is how it looks based on above code. We can see that it is creating RowSpan.
This is how it looks based on above code. We can see that it is creating RowSpan.



This is how it should look at the end
This is what I'm expecting to do.



The only problem is - While Setting RowSpan it is not refreshing the subsequent cells. Because, I'm applying the RowSpan in Runtime after the Grid and all the Cells are created. How can I refresh the Grid and other remaining cells to moved to their own cells?



Thank you for helping me.










share|improve this question



























    0














    I have a generic Grid List Control. Which let me Bind the Item Source and ItemTemplate and it will generates the Column and Rows based on Number of Items or Based on how Users set the Rows and Columns. Its perfect until here. It supports all the generics I needed.



    Now the Problem part:
    I have a ContentView which will be used as Item Template for the Grid. This Template will be used for Multiple Data Types. I'm able to do it properly. Now I have one Data Type Where the First Cell should have RowSpan if it meets certain condition: The code below works perfect. It creates the RowSpan perfectly.



        bool isYearBuilt = false;
    bool isAny = false;

    public FilterItemView()
    {
    InitializeComponent();
    }

    protected override void OnBindingContextChanged()
    {
    base.OnBindingContextChanged();

    var context = BindingContext as PropertyFilterItem;
    if (context == null)
    return;

    if(context.FilterType==PropertyFilterTypes.YearBuilt)
    {
    if(context.IsAny)
    {
    isYearBuilt = true; isAny = true;
    }
    }
    }


    protected override void OnParentSet()
    {
    base.OnParentSet();
    GridList grid = this.Parent as GridList;
    if (grid == null)
    return;

    if(isYearBuilt && isAny)
    {
    Grid.SetRowSpan(this, 2);
    }
    }


    These are the Images; which will describe it more perfectly:
    This is how it looks based on above code. We can see that it is creating RowSpan.
    This is how it looks based on above code. We can see that it is creating RowSpan.



    This is how it should look at the end
    This is what I'm expecting to do.



    The only problem is - While Setting RowSpan it is not refreshing the subsequent cells. Because, I'm applying the RowSpan in Runtime after the Grid and all the Cells are created. How can I refresh the Grid and other remaining cells to moved to their own cells?



    Thank you for helping me.










    share|improve this question

























      0












      0








      0







      I have a generic Grid List Control. Which let me Bind the Item Source and ItemTemplate and it will generates the Column and Rows based on Number of Items or Based on how Users set the Rows and Columns. Its perfect until here. It supports all the generics I needed.



      Now the Problem part:
      I have a ContentView which will be used as Item Template for the Grid. This Template will be used for Multiple Data Types. I'm able to do it properly. Now I have one Data Type Where the First Cell should have RowSpan if it meets certain condition: The code below works perfect. It creates the RowSpan perfectly.



          bool isYearBuilt = false;
      bool isAny = false;

      public FilterItemView()
      {
      InitializeComponent();
      }

      protected override void OnBindingContextChanged()
      {
      base.OnBindingContextChanged();

      var context = BindingContext as PropertyFilterItem;
      if (context == null)
      return;

      if(context.FilterType==PropertyFilterTypes.YearBuilt)
      {
      if(context.IsAny)
      {
      isYearBuilt = true; isAny = true;
      }
      }
      }


      protected override void OnParentSet()
      {
      base.OnParentSet();
      GridList grid = this.Parent as GridList;
      if (grid == null)
      return;

      if(isYearBuilt && isAny)
      {
      Grid.SetRowSpan(this, 2);
      }
      }


      These are the Images; which will describe it more perfectly:
      This is how it looks based on above code. We can see that it is creating RowSpan.
      This is how it looks based on above code. We can see that it is creating RowSpan.



      This is how it should look at the end
      This is what I'm expecting to do.



      The only problem is - While Setting RowSpan it is not refreshing the subsequent cells. Because, I'm applying the RowSpan in Runtime after the Grid and all the Cells are created. How can I refresh the Grid and other remaining cells to moved to their own cells?



      Thank you for helping me.










      share|improve this question













      I have a generic Grid List Control. Which let me Bind the Item Source and ItemTemplate and it will generates the Column and Rows based on Number of Items or Based on how Users set the Rows and Columns. Its perfect until here. It supports all the generics I needed.



      Now the Problem part:
      I have a ContentView which will be used as Item Template for the Grid. This Template will be used for Multiple Data Types. I'm able to do it properly. Now I have one Data Type Where the First Cell should have RowSpan if it meets certain condition: The code below works perfect. It creates the RowSpan perfectly.



          bool isYearBuilt = false;
      bool isAny = false;

      public FilterItemView()
      {
      InitializeComponent();
      }

      protected override void OnBindingContextChanged()
      {
      base.OnBindingContextChanged();

      var context = BindingContext as PropertyFilterItem;
      if (context == null)
      return;

      if(context.FilterType==PropertyFilterTypes.YearBuilt)
      {
      if(context.IsAny)
      {
      isYearBuilt = true; isAny = true;
      }
      }
      }


      protected override void OnParentSet()
      {
      base.OnParentSet();
      GridList grid = this.Parent as GridList;
      if (grid == null)
      return;

      if(isYearBuilt && isAny)
      {
      Grid.SetRowSpan(this, 2);
      }
      }


      These are the Images; which will describe it more perfectly:
      This is how it looks based on above code. We can see that it is creating RowSpan.
      This is how it looks based on above code. We can see that it is creating RowSpan.



      This is how it should look at the end
      This is what I'm expecting to do.



      The only problem is - While Setting RowSpan it is not refreshing the subsequent cells. Because, I'm applying the RowSpan in Runtime after the Grid and all the Cells are created. How can I refresh the Grid and other remaining cells to moved to their own cells?



      Thank you for helping me.







      xamarin.forms






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 19 '18 at 19:31









      Nirmal SubediNirmal Subedi

      1,4262823




      1,4262823
























          3 Answers
          3






          active

          oldest

          votes


















          0














          Set the grid list's ItemsSource = null and set it back again to the item source you want.






          share|improve this answer





















          • I can only access ItemSource in the Page. The Code above is inside the ItemTemplate. Which can only access the ITEM which is getting binded to the Current View.
            – Nirmal Subedi
            Nov 20 '18 at 15:14





















          0














          Cause of the problem:



          As you have said, While Setting RowSpan it is not refreshing the subsequent cells.



          Solution:



          After you have set rowspan using Grid.SetRowSpan(this, 2); you have to bind the datasource again.






          share|improve this answer























          • I can only access ItemSource in the Page. The Code above is inside the ItemTemplate. Which can only access the ITEM which is getting binded to the Current View.
            – Nirmal Subedi
            Nov 20 '18 at 15:14





















          0














          Since I had my own Custom Grid List control. I implemented more Properties which let me know When I have to RowSpan for Child View in Grid and Adjust subsequent Child items. That was the only best way to deal with this problem rather than re-assigning the ItemSource property. Because, If we assign item source it will redraw all the items (including the rows and columns - not row/colspans). So we would still end up with same issue.



          Solution: Added RowSpan logic in my Grid Control.






          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%2f53381427%2fxamarin-forms-grid-conditional-rowspan%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Set the grid list's ItemsSource = null and set it back again to the item source you want.






            share|improve this answer





















            • I can only access ItemSource in the Page. The Code above is inside the ItemTemplate. Which can only access the ITEM which is getting binded to the Current View.
              – Nirmal Subedi
              Nov 20 '18 at 15:14


















            0














            Set the grid list's ItemsSource = null and set it back again to the item source you want.






            share|improve this answer





















            • I can only access ItemSource in the Page. The Code above is inside the ItemTemplate. Which can only access the ITEM which is getting binded to the Current View.
              – Nirmal Subedi
              Nov 20 '18 at 15:14
















            0












            0








            0






            Set the grid list's ItemsSource = null and set it back again to the item source you want.






            share|improve this answer












            Set the grid list's ItemsSource = null and set it back again to the item source you want.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 20 '18 at 5:15









            iamlawrenceviamlawrencev

            636




            636












            • I can only access ItemSource in the Page. The Code above is inside the ItemTemplate. Which can only access the ITEM which is getting binded to the Current View.
              – Nirmal Subedi
              Nov 20 '18 at 15:14




















            • I can only access ItemSource in the Page. The Code above is inside the ItemTemplate. Which can only access the ITEM which is getting binded to the Current View.
              – Nirmal Subedi
              Nov 20 '18 at 15:14


















            I can only access ItemSource in the Page. The Code above is inside the ItemTemplate. Which can only access the ITEM which is getting binded to the Current View.
            – Nirmal Subedi
            Nov 20 '18 at 15:14






            I can only access ItemSource in the Page. The Code above is inside the ItemTemplate. Which can only access the ITEM which is getting binded to the Current View.
            – Nirmal Subedi
            Nov 20 '18 at 15:14















            0














            Cause of the problem:



            As you have said, While Setting RowSpan it is not refreshing the subsequent cells.



            Solution:



            After you have set rowspan using Grid.SetRowSpan(this, 2); you have to bind the datasource again.






            share|improve this answer























            • I can only access ItemSource in the Page. The Code above is inside the ItemTemplate. Which can only access the ITEM which is getting binded to the Current View.
              – Nirmal Subedi
              Nov 20 '18 at 15:14


















            0














            Cause of the problem:



            As you have said, While Setting RowSpan it is not refreshing the subsequent cells.



            Solution:



            After you have set rowspan using Grid.SetRowSpan(this, 2); you have to bind the datasource again.






            share|improve this answer























            • I can only access ItemSource in the Page. The Code above is inside the ItemTemplate. Which can only access the ITEM which is getting binded to the Current View.
              – Nirmal Subedi
              Nov 20 '18 at 15:14
















            0












            0








            0






            Cause of the problem:



            As you have said, While Setting RowSpan it is not refreshing the subsequent cells.



            Solution:



            After you have set rowspan using Grid.SetRowSpan(this, 2); you have to bind the datasource again.






            share|improve this answer














            Cause of the problem:



            As you have said, While Setting RowSpan it is not refreshing the subsequent cells.



            Solution:



            After you have set rowspan using Grid.SetRowSpan(this, 2); you have to bind the datasource again.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 20 '18 at 8:04

























            answered Nov 20 '18 at 7:17









            AbbyWangAbbyWang

            1615




            1615












            • I can only access ItemSource in the Page. The Code above is inside the ItemTemplate. Which can only access the ITEM which is getting binded to the Current View.
              – Nirmal Subedi
              Nov 20 '18 at 15:14




















            • I can only access ItemSource in the Page. The Code above is inside the ItemTemplate. Which can only access the ITEM which is getting binded to the Current View.
              – Nirmal Subedi
              Nov 20 '18 at 15:14


















            I can only access ItemSource in the Page. The Code above is inside the ItemTemplate. Which can only access the ITEM which is getting binded to the Current View.
            – Nirmal Subedi
            Nov 20 '18 at 15:14






            I can only access ItemSource in the Page. The Code above is inside the ItemTemplate. Which can only access the ITEM which is getting binded to the Current View.
            – Nirmal Subedi
            Nov 20 '18 at 15:14













            0














            Since I had my own Custom Grid List control. I implemented more Properties which let me know When I have to RowSpan for Child View in Grid and Adjust subsequent Child items. That was the only best way to deal with this problem rather than re-assigning the ItemSource property. Because, If we assign item source it will redraw all the items (including the rows and columns - not row/colspans). So we would still end up with same issue.



            Solution: Added RowSpan logic in my Grid Control.






            share|improve this answer


























              0














              Since I had my own Custom Grid List control. I implemented more Properties which let me know When I have to RowSpan for Child View in Grid and Adjust subsequent Child items. That was the only best way to deal with this problem rather than re-assigning the ItemSource property. Because, If we assign item source it will redraw all the items (including the rows and columns - not row/colspans). So we would still end up with same issue.



              Solution: Added RowSpan logic in my Grid Control.






              share|improve this answer
























                0












                0








                0






                Since I had my own Custom Grid List control. I implemented more Properties which let me know When I have to RowSpan for Child View in Grid and Adjust subsequent Child items. That was the only best way to deal with this problem rather than re-assigning the ItemSource property. Because, If we assign item source it will redraw all the items (including the rows and columns - not row/colspans). So we would still end up with same issue.



                Solution: Added RowSpan logic in my Grid Control.






                share|improve this answer












                Since I had my own Custom Grid List control. I implemented more Properties which let me know When I have to RowSpan for Child View in Grid and Adjust subsequent Child items. That was the only best way to deal with this problem rather than re-assigning the ItemSource property. Because, If we assign item source it will redraw all the items (including the rows and columns - not row/colspans). So we would still end up with same issue.



                Solution: Added RowSpan logic in my Grid Control.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 20 '18 at 17:37









                Nirmal SubediNirmal Subedi

                1,4262823




                1,4262823






























                    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%2f53381427%2fxamarin-forms-grid-conditional-rowspan%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

                    MongoDB - Not Authorized To Execute Command

                    How to fix TextFormField cause rebuild widget in Flutter

                    Npm cannot find a required file even through it is in the searched directory