This is a migrated thread and some comments may be shown as answers.

GridView CellTemplate Binding Errors

9 Answers 215 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 1
Adam asked on 03 May 2012, 12:53 PM

Hello Telerik,

This is probably a silly question with an obvious answer - but I am having issues with my CellTemplate content binding...
<telerik:RadGridView x:Name="GridViewDetailAC"
                AutoGenerateColumns="False"
                AlternateRowBackground="White"
                AlternationCount="2"
                AllowDrop="True"
                CanUserSelect="True"
                CanUserDeleteRows="False"
                CanUserInsertRows="False"
                CanUserResizeColumns="True"
                EditTriggers="None"
                Grid.Row="1"
                Grid.Column="0"
                Grid.ColumnSpan="4"
                HorizontalGridLinesBrush="SlateGray"
                ItemsSource="{Binding XXXX}"
                RowIndicatorVisibility="Collapsed"
                RowHeight="26"
                SelectedItem="{Binding Path=SelectedXXXX,
                                NotifyOnSourceUpdated=True
                                UpdateSourceTrigger=PropertyChanged}"
                SelectionMode="Single"
                SelectionUnit="FullRow"                                                                    
                ShowColumnFooters="False"
                ShowGroupPanel="False"
                ShowColumnHeaders="True"
                VerticalGridLinesBrush="Transparent">
    <telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn Header="Vendor"
                            Width="Auto"
                            TextAlignment="Left"
                            IsVisible="{Binding ElementName=ckbVendorVisi,
                                          Path=IsChecked,
                                          FallbackValue=0}">
            <telerik:GridViewDataColumn.CellTemplate>
                <DataTemplate>
                    <DockPanel>
                        <Label Content="{Binding Path=LV_Name, FallbackValue=''}"
                             Visibility="{Binding Path=NotNewRecord,
                                            FallbackValue=0,
                                            Converter={StaticResource BoolVisiRevConv2}}"/>
                        <TextBox  Text="{Binding Path=LV_Name, FallbackValue=''}"
                              Visibility="{Binding Path=NotNewRecord,
                                             FallbackValue=0,
                                             Converter={StaticResource BoolVisiConv2}}"/>
            </DockPanel>
        </DataTemplate>
    </telerik:GridViewDataColumn.CellTemplate>
</telerik:GridViewDataColumn>

The above piece of code, using MVVM, produces a 'System.Windows.Data Information XX' errors - Three to be exact: 41, 20, 21 for each ViewModel property binding.
System.Windows.Data Information: 41 : BindingExpression path error: 'LV_Name' property not found for 'object' because data item is null.  This could happen because the data provider has not produced any data yet. BindingExpression:Path=LV_Name; DataItem=null; target element is 'Label' (Name=''); target property is 'Content' (type 'Object')
System.Windows.Data Information: 20 : BindingExpression cannot retrieve value due to missing information. BindingExpression:Path=LV_Name; DataItem=null; target element is 'Label' (Name=''); target property is 'Content' (type 'Object')
System.Windows.Data Information: 21 : BindingExpression cannot retrieve value from null data item. This could happen when binding is detached or when binding to a Nullable type that has no value. BindingExpression:Path=LV_Name; DataItem=null; target element is 'Label' (Name=''); target property is 'Content' (type 'Object')
System.Windows.Data Information: 41 : BindingExpression path error: 'NotNewRecord' property not found for 'object' because data item is null.  This could happen because the data provider has not produced any data yet. BindingExpression:Path=NotNewRecord; DataItem=null; target element is 'Label' (Name=''); target property is 'Visibility' (type 'Visibility')
System.Windows.Data Information: 20 : BindingExpression cannot retrieve value due to missing information. BindingExpression:Path=NotNewRecord; DataItem=null; target element is 'Label' (Name=''); target property is 'Visibility' (type 'Visibility')
System.Windows.Data Information: 21 : BindingExpression cannot retrieve value from null data item. This could happen when binding is detached or when binding to a Nullable type that has no value. BindingExpression:Path=NotNewRecord; DataItem=null; target element is 'Label' (Name=''); target property is 'Visibility' (type 'Visibility')
System.Windows.Data Information: 41 : BindingExpression path error: 'LV_Name' property not found for 'object' because data item is null.  This could happen because the data provider has not produced any data yet. BindingExpression:Path=LV_Name; DataItem=null; target element is 'TextBox' (Name=''); target property is 'Text' (type 'String')
System.Windows.Data Information: 20 : BindingExpression cannot retrieve value due to missing information. BindingExpression:Path=LV_Name; DataItem=null; target element is 'TextBox' (Name=''); target property is 'Text' (type 'String')
System.Windows.Data Information: 21 : BindingExpression cannot retrieve value from null data item. This could happen when binding is detached or when binding to a Nullable type that has no value. BindingExpression:Path=LV_Name; DataItem=null; target element is 'TextBox' (Name=''); target property is 'Text' (type 'String')
System.Windows.Data Information: 41 : BindingExpression path error: 'NotNewRecord' property not found for 'object' because data item is null.  This could happen because the data provider has not produced any data yet. BindingExpression:Path=NotNewRecord; DataItem=null; target element is 'TextBox' (Name=''); target property is 'Visibility' (type 'Visibility')
System.Windows.Data Information: 20 : BindingExpression cannot retrieve value due to missing information. BindingExpression:Path=NotNewRecord; DataItem=null; target element is 'TextBox' (Name=''); target property is 'Visibility' (type 'Visibility')
System.Windows.Data Information: 21 : BindingExpression cannot retrieve value from null data item. This could happen when binding is detached or when binding to a Nullable type that has no value. BindingExpression:Path=NotNewRecord; DataItem=null; target element is 'TextBox' (Name=''); target property is 'Visibility' (type 'Visibility')

If I swap the CellTemplate out and use the DataMemberBidning property on the GridViewDataColumn then no binding error(s) occur - BUT I require the dual content hide/show feature.

I have also attempted to use the other types of GridViewColumn available but that seemed to make little difference in the outcome.

Can you help me determin why my non-null ItemsSource and its non-null properties are not being friendly with your RadGridView's columns?


Cheers,

9 Answers, 1 is accepted

Sort by
0
Adam
Top achievements
Rank 1
answered on 03 May 2012, 03:10 PM


UPDATE:

In case this is not know, it would appear that these Binding Errors (that seem to be slowing down executing considerably) are occuring before the get { } attribute for any property is called...

So if the data being bound is NOT null is the Binding for the CellTemplate is working faster then the ItemsSource?
Does anybody have an efficent way of producing the desired results?
(I was hoping to avoid using CellTemplateSelectors as I think they would be less efficent than binding visibility properties)
0
Dimitrina
Telerik team
answered on 04 May 2012, 08:13 AM
Hello,

The error says that the DataItem is null. May I ask you to do a simple test? What is the result if you remove all the CellTemlates and CellEditTemplates?

Greetings,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Adam
Top achievements
Rank 1
answered on 04 May 2012, 11:15 AM

Hello Didie,

    If I remove all the CellTemplates/CellEditTemplates and just use the DatamemberBinding property then the Grid scrolls smoothly (no Information/Warning/Error messages are displayed/generated within the Output window).

My MVVM model is similar, though alittle more complex, to this:
public class DetailsClass : INotifyPropertyChanged
{
    Boolean notnewrecord;
 
    public Boolean NotNewRecord
    {
        get { return notnewrecord; }
        set
        {
            if (notnewrecord != value)
            {
                notnewrecord = value;
                RaisePropertyChanged("NotNewRecord");
            }
        }
    }
 
    public event PropertyChangedEventHandler PropertyChanged;
 
    private void RaisePropertyChanged(string propertyName)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null)
        {
            handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
 
public class ViewClass : INotifyPropertyChanged
{
    public ObservableCollection<DetailsClass> DetailsBAMCollection   { get; set; }
 
    public event PropertyChangedEventHandler PropertyChanged;
 
    private void RaisePropertyChanged(string propertyName)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null)
        {
            handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

ViewClass is assigned to the Windows DataCOntext (this.DataContext) within its constructor and the RadGridView's ItemsSource is bound to the ObservableCollection<DetailsClass>.
0
Adam
Top achievements
Rank 1
answered on 04 May 2012, 11:23 AM
I tried this:
<telerik:GridViewDataColumn.CellTemplate>
  <DataTemplate>
    <Grid HorizontalAlignment="Stretch">
      <Button Style="{StaticResource FlatButton}" HorizontalAlignment="Center">
        <Image Height="16"
             Width="16"
             Source="/MaterialsInvoiceClearanceNew;component/Views/Images/information.png">
          <Image.Style>
            <Style TargetType="{x:Type Image}">
              <Style.Triggers>
                <DataTrigger Binding="{Binding RelativeSource={RelativeSource
                                      AncestorType={x:Type Button},                            PresentationTraceSources.TraceLevel=High,
                                      Path=DataContext.NotNewRecord,
                                      FallbackValue=0}" Value="False">
                  <Setter Property="Source" Value="/MaterialsInvoiceClearanceNew;component/Views/Images/add.png"/>
                </DataTrigger>
              </Style.Triggers>
            </Style>
          </Image.Style>
        </Image>  
      </Button>
    </Grid>                                                               
  </DataTemplate>
</telerik:GridViewDataColumn.CellTemplate>

and recieved this in the Output window:
System.Windows.Data Warning: 94 : BindingExpression (hash=18757587): Got PropertyChanged event from Button (hash=17033130) for DataContext
System.Windows.Data Warning: 99 : BindingExpression (hash=18757587): GetValue at level 0 from Button (hash=17033130) using DependencyProperty(DataContext): <null>
System.Windows.Data Warning: 104 : BindingExpression (hash=18757587):   Item at level 1 is null - no accessor
System.Windows.Data Information: 41 : BindingExpression path error: 'NotNewRecord' property not found for 'object' because data item is null.  This could happen because the data provider has not produced any data yet. BindingExpression:Path=DataContext.NotNewRecord; DataItem='Button' (Name=''); target element is 'Image' (Name=''); target property is 'NoTarget' (type 'Object')
System.Windows.Data Information: 20 : BindingExpression cannot retrieve value due to missing information. BindingExpression:Path=DataContext.NotNewRecord; DataItem='Button' (Name=''); target element is 'Image' (Name=''); target property is 'NoTarget' (type 'Object')
System.Windows.Data Information: 21 : BindingExpression cannot retrieve value from null data item. This could happen when binding is detached or when binding to a Nullable type that has no value. BindingExpression:Path=DataContext.NotNewRecord; DataItem='Button' (Name=''); target element is 'Image' (Name=''); target property is 'NoTarget' (type 'Object')
System.Windows.Data Warning: 78 : BindingExpression (hash=18757587): TransferValue - got raw value {DependencyProperty.UnsetValue}
System.Windows.Data Warning: 86 : BindingExpression (hash=18757587): TransferValue - using fallback/default value '0'
System.Windows.Data Warning: 87 : BindingExpression (hash=18757587): TransferValue - using final value '0'
System.Windows.Data Warning: 94 : BindingExpression (hash=18757587): Got PropertyChanged event from Button (hash=17033130) for DataContext
System.Windows.Data Warning: 99 : BindingExpression (hash=18757587): GetValue at level 0 from Button (hash=17033130) using DependencyProperty(DataContext): DetailsClass (hash=63547070)
System.Windows.Data Warning: 105 : BindingExpression (hash=18757587):   At level 1 using cached accessor for DetailsClass.NotNewRecord: RuntimePropertyInfo(NotNewRecord)
System.Windows.Data Warning: 102 : BindingExpression (hash=18757587): Replace item at level 1 with DetailsClass (hash=63547070), using accessor RuntimePropertyInfo(NotNewRecord)
System.Windows.Data Warning: 99 : BindingExpression (hash=18757587): GetValue at level 1 from DetailsClass (hash=63547070) using RuntimePropertyInfo(NotNewRecord): 'True'
System.Windows.Data Warning: 78 : BindingExpression (hash=18757587): TransferValue - got raw value 'True'
System.Windows.Data Warning: 87 : BindingExpression (hash=18757587): TransferValue - using final value 'True'
0
Dimitrina
Telerik team
answered on 08 May 2012, 12:21 PM
Hello,

It says that there is not an item: "'NotNewRecord' property not found for 'object' because data item is null.  This could happen because the data provider has not produced any data yet."

Would it be possible to send me a simple project showing the errors? That way I can debug that case locally.

All the best,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Adam
Top achievements
Rank 1
answered on 08 May 2012, 02:48 PM

Hello again Didie,

    Tha examples above are the cut-down version I ended up using to re-test my problem... I have since changed my Output Window's WPF Trace Settings to "Error" instead of the previous "All", which has removed alot of the code generated.

I believe I have been overloading the control (RadGridView) and looking for a execution scapegoat, which is where the Output Window came in. Please let me know what you think about this.
0
Dimitrina
Telerik team
answered on 09 May 2012, 09:44 AM
Hi,

 I can see one error in the snippet of the Output window. 

In my opinion the problem is in this Binding: 

<DataTrigger Binding="{Binding RelativeSource={RelativeSource
                                      AncestorType={x:Type Button},                            PresentationTraceSources.TraceLevel=High,
                                      Path=DataContext.NotNewRecord,
                                      FallbackValue=0}" Value="False">
                  <Setter Property="Source" Value="/MaterialsInvoiceClearanceNew;component/Views/Images/add.png"/>
                </DataTrigger>

Please note that a '}' is missing after 'PresentationTraceSources.TraceLevel=High'. 

All the best,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Adam
Top achievements
Rank 1
answered on 09 May 2012, 10:11 AM

That is probably a type-o made during edit for the forum post... as the missing bracket would probably cause the system to crash?
0
Dimitrina
Telerik team
answered on 09 May 2012, 12:22 PM
Hi,

 I have run the code snippet in a test project at my end, but I did not got any binding errors. I could further investigate the case if you send me a sample project to show the Error.

Greetings,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Adam
Top achievements
Rank 1
Answers by
Adam
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or