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!