Home Forums WPF controls Xceed DataGrid for WPF Binding Canvas to two xceed datagrids

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • dronvg
    Post count: 4
    #44733 |

    Hello, need some help to figure this out!

    I have TWO datagrids that have the same source (BindingList)
    I am dynamically creating few elements inside the canvas (also tried grid, but in my case canvas works the best)
    Canvas column has a binding like this:

    <xcdg:Column FieldName="LVCanvas" Title="Figs" Width="80"  AllowGroup="False" AllowSort="False" CanBeCurrentWhenReadOnly="False" MinWidth="79" CellHorizontalContentAlignment="Center" MaxWidth="80" >
                                <ContentPresenter Content="{Binding}"  />

    My Problem is that the canvas is only shows in 2nd Datagrid, fist datagrid shows empty column.
    if I set visibility to collapse on the column on 2nd Datagrid, canvas shows normally in 1st datagrid and visa-versa.

    I am very hopeful to get some help on this. Please and thank you!

    Fawzi [Xceed]
    Post count: 722


    Could you send me a simple stand alone sample project which reproduces the issue so that I could have a closer look. You may send it to: support@xceed.com

    Fawzi [Xceed]
    Post count: 722


    The issue here is related to the way the WPF Framework works. The Canvas that is set in a “data item” property is a Visual. To be displayed, a Visual object has to be inserted somewhere down the VisualTree. The same Visual instance cannot be located at 2 different locations in the VisualTree. When a Visual is inserted a second time in the VisualTree, the WPF Framework will remove it from its current location and insert it at its new location.

    In the scenario, the Canvas that is located in the first DataGridControl is being removed by the WPF Framework from the first DataGridControl and inserted under the second DataGridControl since it cannot be located at 2 different locations in the VisualTree. In order to work, each grid must have their own “instance” of the Canvas. This cannot work since both grids share the same data source/data items.

    One solution that may work is to replace the property of type Canvas on the data item for a property of type DataTemplate. A DataTemplate can be shared by more than one control in WPF. When used, each control will create its own instance of the control based on the DataTemplate. So, if a DataTemplate is set to create a Canvas, each DataGridControl will create its own instance of Canvas.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.