Binding Issues After Converting a WPF DataGrid to a C1DataGrid

Posted by: nkleewein on 25 June 2018, 4:47 am EST

    • Post Options:
    • Link

    Posted 25 June 2018, 4:47 am EST

    I recently converted a WPF DataGrid to a C1DataGrid and have been having issues with binding to a property that resides in a separate class. Below is the XAML for the C1DataGrid:

    <QuickEntryMutliSkuPopup:DataGridCopyAndPaste x:Name="DataGridCopyAndPaste" 
                                        AutoGenerateColumns="False"    
                                        Grid.Row="5" Grid.Column="0"                                  
                                         Background="Transparent"
                                         RowHeaderWidth="25"
                                         RowHeight="25"                     
                                         RowBackground="White" 
                                         CanUserAddRows="False"
                                         CanUserReorderColumns="False"
                                         CanUserResizeColumns="False"
                                         HorizontalScrollBarVisibility="Auto"
                                         SelectionMode="MultiRange"
                                         Height="300" CanUserSort="False" CanUserResizeRows="False" CanUserRemoveRows="False">
                            <QuickEntryMutliSkuPopup:DataGridCopyAndPaste.Columns>
                                <C1Grid:DataGridTextColumn Width="150" 
                                                           Header="Full Product Number" 
                                                           Binding="{Binding Path=ProductfullName}"
                                                           EditOnSelection="False">
                                    <C1Grid:DataGridTextColumn.CellStyle>
                                        <Style TargetType="{x:Type C1Grid:DataGridCellPresenter}">
                                            <Setter Property="Foreground" Value="Black"/>
                                            <Setter Property="Background" Value="{Binding DataRowBackgroundColor, Converter={StaticResource cnvDataGridCopyAndPasterConverter}, ConverterParameter=Background, diag:PresentationTraceSources.TraceLevel=High}" />
                                            <Setter Property="ToolTip" Value="{Binding DataRowBackgroundColor, Converter={StaticResource cnvDataGridCopyAndPasterConverter}, ConverterParameter=ToolTip, diag:PresentationTraceSources.TraceLevel=High}" />
                                        </Style>
                                    </C1Grid:DataGridTextColumn.CellStyle>
                                </C1Grid:DataGridTextColumn>
                            </QuickEntryMutliSkuPopup:DataGridCopyAndPaste.Columns>
                            <C1Grid:C1DataGrid.CellStyle>
                                <Style TargetType="{x:Type C1Grid:DataGridCellPresenter}">
                                    <Style.Setters>
                                    <Setter Property="ToolTipService.ShowOnDisabled" Value="True" />
                                    <Setter Property="Foreground" Value="Black"/>
                                        <Setter Property="Background" Value="{Binding DataRowBackgroundColor, Converter={StaticResource cnvDataGridCopyAndPasterConverter}, ConverterParameter=Background, diag:PresentationTraceSources.TraceLevel=High}" />
                                        <Setter Property="ToolTip" Value="{Binding DataRowBackgroundColor, Converter={StaticResource cnvDataGridCopyAndPasterConverter}, ConverterParameter=ToolTip, diag:PresentationTraceSources.TraceLevel=High}" />
                                        <Setter Property="IsEnabled" Value="{Binding DataRowBackgroundColor, Converter={StaticResource cnvDataGridCopyAndPasterConverter}, ConverterParameter=IsEnabled, diag:PresentationTraceSources.TraceLevel=High}" />
                                    </Style.Setters>
                                </Style>
                            </C1Grid:C1DataGrid.CellStyle>
                        </QuickEntryMutliSkuPopup:DataGridCopyAndPaste>
    

    The issue I am running into is on the following:

    The DataRowBackroundColor property exists in another class file. WPF didn’t have a problem with getting the correct root item. Below is a snippet from the output window when running the app with a WPF DataGrid:

    System.Windows.Data Warning: 60 : BindingExpression (hash=30291272): Default mode resolved to OneWay

    System.Windows.Data Warning: 61 : BindingExpression (hash=30291272): Default update trigger resolved to PropertyChanged

    System.Windows.Data Warning: 62 : BindingExpression (hash=30291272): Attach to Microsoft.Windows.Controls.DataGridCell.ToolTip (hash=39809767)

    System.Windows.Data Warning: 67 : BindingExpression (hash=30291272): Resolving source

    System.Windows.Data Warning: 70 : BindingExpression (hash=30291272): Found data context element: DataGridCell (hash=39809767) (OK)

    System.Windows.Data Warning: 78 : BindingExpression (hash=30291272): Activate with root item CopyAndPasteProduct (hash=51183840)

    System.Windows.Data Warning: 107 : BindingExpression (hash=30291272): At level 0 using cached accessor for CopyAndPasteProduct.DataRowBackgroundColor: RuntimePropertyInfo(DataRowBackgroundColor)

    System.Windows.Data Warning: 104 : BindingExpression (hash=30291272): Replace item at level 0 with CopyAndPasteProduct (hash=51183840), using accessor RuntimePropertyInfo(DataRowBackgroundColor)

    System.Windows.Data Warning: 101 : BindingExpression (hash=30291272): GetValue at level 0 from CopyAndPasteProduct (hash=51183840) using RuntimePropertyInfo(DataRowBackgroundColor): ‘’

    System.Windows.Data Warning: 80 : BindingExpression (hash=30291272): TransferValue - got raw value ‘’

    System.Windows.Data Warning: 82 : BindingExpression (hash=30291272): TransferValue - user’s converter produced

    System.Windows.Data Warning: 89 : BindingExpression (hash=30291272): TransferValue - using final value

    System.Windows.Data Warning: 56 : Created BindingExpression (hash=37673953) for Binding (hash=54474048)

    However, when I run the app with the C1DataGrid, I get the following output:

    System.Windows.Data Warning: 60 : BindingExpression (hash=57980147): Default mode resolved to OneWay

    System.Windows.Data Warning: 61 : BindingExpression (hash=57980147): Default update trigger resolved to PropertyChanged

    System.Windows.Data Warning: 62 : BindingExpression (hash=57980147): Attach to C1.WPF.DataGrid.DataGridCellPresenter.ToolTip (hash=13898779)

    System.Windows.Data Warning: 67 : BindingExpression (hash=57980147): Resolving source

    System.Windows.Data Warning: 70 : BindingExpression (hash=57980147): Found data context element: DataGridCellPresenter (hash=13898779) (OK)

    System.Windows.Data Warning: 71 : BindingExpression (hash=57980147): DataContext is null


    System.Windows.Data Warning: 65 : BindingExpression (hash=57980147): Resolve source deferred

    System.Windows.Data Warning: 56 : Created BindingExpression (hash=52059282) for Binding (hash=30123835)

    And I also get the following error(s) in the output window:

    System.Windows.Data Error: 40 : BindingExpression path error: ‘DataRowBackgroundColor’ property not found on ‘object’ ‘‘MainWindow’ (Name=‘root’)’. BindingExpression:Path=DataRowBackgroundColor; DataItem=‘MainWindow’ (Name=‘root’); target element is ‘DataGridCellPresenter’ (Name=‘’); target property is ‘ToolTip’ (type ‘Object’)

    I’m not exactly sure why the C1DataGrid is looking for the DataRowBackgroundColor property in MainWindow, and I’ve been banging my head against the wall for a few days now trying to figure it out.

    The app is supposed to hit the converter in the MainWindow code-behind, but without the correct property binding, the converter never gets hit.

    I have uploaded a sample app with a simple implementation to reproduce the issue.

    Any help would be greatly appreciated!

  • Posted 25 June 2018, 4:48 am EST

    Sorry, here is the sample app:

    QuickEntryMultiSkuPopup.zip

  • Posted 27 June 2018, 1:07 am EST

    Hi,

    After setting the ItemsSource, you also need to set the DataContext of the C1DataGrid, as follows:```

    DataGridCopyAndPaste.ItemsSource = null;

    DataGridCopyAndPaste.ItemsSource = new CopyAndPasteProducts();

    DataGridCopyAndPaste.DataContext = new CopyAndPasteProduct()

    
    Regards,
    Ruchir 
    [zip filename="QuickEntryMultiSkuPopup_modified.zip"]https://gccontent.blob.core.windows.net/forum-uploads/file-8c9b3bd6-2bac-4be5-9e6c-6287ab2187e8.zip[/zip]
  • Posted 27 June 2018, 4:23 am EST

    Thank you for the help, I knew I was missing something simple!

    So the clsDataGridCopyAndPasterConverter converter is now getting hit when the grid loads, which is perfect, however, when I actually paste values into the Full Product Number column in the grid, the clsDataGridCopyAndPasterConverter is not getting hit at all. Basically, I am needing to validate the data getting copied into the Full Product Number column, and if, let’s say, the length of the Full Product Number is 3 characters, then I need to set the DataRowBackgroundColor property to Light Gray, and set the ToolTip property to some string value so the end user has an indication that something is incorrect with the data they’ve pasted.

    Any ideas as to why the converter isn’t getting hit?

  • Posted 27 June 2018, 5:33 pm EST

    Hi,

    For validating the data at run-time, C1DataGrid provides C1ValidationBehavior using which an alert symbol, different border, tooltips would be shown if the validation fails for any cell (of specific columns(s)). I have implemented the same in your sample application and attached here for your reference. Hence, I suggest you to try the same.

    Thanks,

    Ruchir

    QuickEntryMultiSkuPopup_validation.zip

  • Posted 28 June 2018, 4:53 am EST

    Thank you, that’s exactly what I was looking for!

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels