Skip to main content

Microsoft Silverlight

Answered Question Grid's RowDefinitions.Insert does not behave as I would expectRSS Feed

(0)

jpsscott
jpsscott

Member

Member

51 points

84 Posts

Grid's RowDefinitions.Insert does not behave as I would expect

I'm playing around with a dynamic Grid layout where I need to insert rows into a grid of pre-existing content.

 When I use the RowDefinitions.Insert() method of the grid and specify an index it doesn't bring the rest of the content down.  Rather it just adds a new line at the end and then I have to manually iterate through all Grid.Children checking the RowProperty and increasing it if its >= my index I inserted the row at.

--------------pseudo code example---------------

// creation of grid with 10 rows of content

grdSomeGrid.RowDefinitions.Insert(5, new RowDefinition());

ContentControl ccContent = new ContentControl();

ccContent.SetValue(Grid.RowProperty, 5);

ccContent.Content = "This will overlap existing content on row 5";

grdSomeGrid.Children.Add(ccContent);

// at this point when the grid is viewed the new content I added overlaps the existing content in grid and to fix it I need to do an RowProperty adjustment for all rows that have content that needs to be pushed down

-------------------------------------------------

 Is this expected behavior?  Any other API I've ever used that has an insert inserts a new item at the index specified and moves all remaining items ahead in the list.

 I've got my workaround of using SetValue to adjust the Grid.RowProperty, but this just seems so awkward.

Any insight?

Thanks,

James

Yi-Lun Luo - MSFT
Yi-Lun L...

All-Star

All-Star

25052 points

2,747 Posts

Re: Grid's RowDefinitions.Insert does not behave as I would expect

Hello, this is by design. It's the same behavior with WPF. You have to manually set the Grid's children's Row properties...

shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.

jpsscott
jpsscott

Member

Member

51 points

84 Posts

Answered Question

Re: Grid's RowDefinitions.Insert does not behave as I would expect

Thanks for the info.

 I have to say, however that this makes no sense at all.

 I guess I'll just have to code around it with my own "helper" function.

James

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities