DataGrid ItemsPanel issue?

Feb 2, 2009 at 1:36 PM
While using the CTP DataGrid I changed the itemsPanel to a regular StackPanel to get around some display issues with the Virtualizing StackPanel.  After upgrading to the V1 DataGrid I noticed my DataGrid wasn't being populated so I started pulling things out one by one and low and behold after removing the itemsPanel from my DataGrid it now works.  Any plans on putting the ability to change the itemsPanel back in to the DataGrid?

Kindest regards,
-LT
Feb 10, 2009 at 5:22 PM
Has anyone else seen this issue?  If so can they confirm this is an issue and if so, will there be a fix?  Just about every other post before and after this one has had a response from someone.  The VirtualizingStackPanel has display issues so I need the ability to use a regular StackPanel for the itemsPanel of the DataGrid.

Kindest regards,
-LT
Coordinator
Feb 10, 2009 at 6:23 PM
Hi LT,

You can change ItemsPanel of DataGrid to regular StackPanel (I can't speak the same about other panels). Following should work....

<dg:DataGrid ...>
        <dg:DataGrid.Resources>
            <Style TargetType="{x:Type ScrollContentPresenter}">
                <Setter Property="CanContentScroll" Value="False"></Setter>
            </Style>
            <Style TargetType="{x:Type ScrollViewer}">
                <Setter Property="CanContentScroll" Value="False"></Setter>
            </Style>
        </dg:DataGrid.Resources>
        <dg:DataGrid.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel></StackPanel>
            </ItemsPanelTemplate>
        </dg:DataGrid.ItemsPanel>
        ....
</dg:DataGrid>


On a side note, what kind of problems do you have with VirtualizingStackPanel?
Feb 10, 2009 at 7:12 PM

Hi,
First thank you for your quick response.

In the CTP version this did work as you describe.  In the V1 release however this no longer works.   If I remove the ItemsPanel on my V1 DataGrid, I can see all of my rows.  If I roll back to the CTP DataGrid and set the ItemsPanel to use a regular StackPanel, I can see all of my rows.

On that side note:
The problem with the VirtualizingStackPanel may really be an issue with the DataGridRowsPresenter and not the underlying VirtualizingStackPanel.  When attempting to style the DataGrid I want the ScrollContentPresenter to have a HorizontalAlignment of Left, so anything in the ScrollContentPresenter with be left aligned instead of stretched to the entire width of the ScrollContentPresenter.  The DataGridRowsPresenter does align to the left as expected but there is a tiny "extra" column added to the right side of the DataGrid.  If I resize my last column, making it larger by dragging it ot the right, it covers this "extra" column.  If I again resize my last column making it smaller that "extra" column now stays the width that my last column was before I made it smaller.  Interacting with the DataGrid by dragging and dropping a row makes that "extra" column snap back to it's original size.  I don't want to see this "extra" column at all, it doesn't line up with the DataGridColumnHeadersPresenter and just looks bad from a design standpoint.  We got around this display issue in the CTP by changing the ItemsPanel for the DataGrid to a regular StackPanel, which now, does not work.

Kindest Regards,
-LT

Coordinator
Feb 11, 2009 at 2:08 AM
Edited Feb 11, 2009 at 2:09 AM
I was able to use a StackPanel as my ItemsPanel. Can you send me a small repro which doesnt work. May be my code or yours have something which makes it work or not.

Also if you can, add another window to the repro project which exhibits the issue with VSP.
Feb 11, 2009 at 2:32 AM
Edited Feb 11, 2009 at 10:10 AM
Absolutely, where should I send it?  I can send you a version that references the CTP wpftoolkit.dll and the V1 release.  I've even tried this with the samples that Vincent Sibal created with the same results.
Coordinator
Feb 11, 2009 at 5:22 PM
Sent you the details through mail.
Feb 12, 2009 at 6:35 PM
Thank you.  I will send a sample shortly, but for what it's worth, this does not just happen with my projects.  If I use samples from Vincent Sibal or Jamie Rodriquez and change the itemsPanel for the DataGrid the same issue occurs.  If I roll back to the CTP DataGrid, everything works correctly.  If I use the October 2008 - 3.5.31016.1 V1 WPFtoolkit.dll or the January 2009 - 3.5.40128.1 V1 WPF toolkit.dll the issue described above occurs.  What version of the WPFToolkit.dll are you using?
Feb 13, 2009 at 8:33 PM
Sample has been sent.  Please let me know if you need any other information.

Kindest regards,
-LT
Coordinator
Feb 16, 2009 at 5:07 PM
Hi LT,

As I said earlier the following works for me on January 2009 - 3.5.40128.1 even with your sample application. See the xaml in bold (that is the difference).

<dg:DataGrid ...>
        <dg:DataGrid.Resources>
            <Style TargetType="{x:Type ScrollContentPresenter}">
                <Setter Property="CanContentScroll" Value="False"></Setter>
            </Style>
            <Style TargetType="{x:Type ScrollViewer}">
                <Setter Property="CanContentScroll" Value="False"></Setter>
            </Style>
        </dg:DataGrid.Resources>

        <dg:DataGrid.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel></StackPanel>
            </ItemsPanelTemplate>
        </dg:DataGrid.ItemsPanel>
        ....
</dg:DataGrid>
Feb 16, 2009 at 8:32 PM
Thank you for your help, your xaml above does indeed work and breaking it down even further you don't need the following:

            <Style TargetType="{x:Type ScrollContentPresenter}">
                <Setter Property="CanContentScroll" Value="False"></Setter>
            </Style>

The difference between the CTP and the V1 release seems very specific to the ScrollViewer and more specifically setting the value of the CanContentScroll Property to "False" in order to get it to work.  If you change it to "True", you lose the data again.  This still seems like an issue to me.  I shouldn't have to change the ScrollViewer at all if I just want to change the ItemsPanel.  What do I do if I need to set the Value of CanContentScroll to True?  Does this change in behavior have to do with moving certain things into Primitives?
Coordinator
Feb 16, 2009 at 8:53 PM
Hi LT,

It is nothing to do with stuff getting moved to Primitives.

DataGridCellsPanel (the panel which arranges the cells within a row) needs scroll information inorder to measure and arrange and if not available it cannot do anything resulting into an empty DataGrid. If ScrollViewer's CanContentScroll is True, DataGridCellsPanel gets the scroll info from ScrollContentPresenter. Else it gets the scroll info from ScrollViewer (which is logical). Now the problem is DataGrid Template definition sets the CanContentScroll to True by default, because we are using VSP by default which can handle scrolling. But that doesnt work with StackPanel, because it cannot handle scroll. Hence the solution with StackPanel is to override this default value to False.

If you want to set the Value of CanContentScroll to true, then you should create your own panel which implements interface IScrollInfo or use an existing panel which implements it (like VSP).
Feb 16, 2009 at 9:06 PM
Thank you so much for the explanation.  The behavior is definitely different in the CTP versus this V1 release but as long as I know what's going on I can work with it.  Thank you for your time and input.

Kindest regards,
-LT