0
votes

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.

3

3 Answers

0
votes

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

0
votes

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.

0
votes

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.