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

Null Reference Exception in XAML

3 Answers 107 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Matthias Bibo
Top achievements
Rank 1
Matthias Bibo asked on 11 Sep 2012, 12:36 PM

Hello,

I changed my binding in the XAML and I got an error:

(It´s nothing tragic, because after a compile the error vanished, so it is only a case, when the binding source changes)

Just for info...

Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.

bei Telerik.Windows.Controls.GridView.BindingExtensions.CloneBinding(Binding source, Boolean forEdit, GridViewValidationMode setValidationMode) in c:\TB\105\WPF_Scrum\Release_SL\Sources\Development\Controls\GridView\GridView\Extensions\BindingExtensions.cs:Zeile 26.
bei Telerik.Windows.Controls.GridViewBoundColumnBase.RefreshValueBindingSetter() in c:\TB\105\WPF_Scrum\Release_SL\Sources\Development\Controls\GridView\GridView\GridView\Columns\GridViewBoundColumnBase.cs:Zeile 965.
bei Telerik.Windows.Controls.GridViewBoundColumnBase.OnDataMemberBindingChanged() in c:\TB\105\WPF_Scrum\Release_SL\Sources\Development\Controls\GridView\GridView\GridView\Columns\GridViewBoundColumnBase.cs:Zeile 942.
bei Telerik.Windows.Controls.GridViewImageColumn.OnDataMemberBindingChanged() in c:\TB\105\WPF_Scrum\Release_SL\Sources\Development\Controls\GridView\GridView\GridView\Columns\GridViewImageColumn.cs:Zeile 112.
bei Telerik.Windows.Controls.GridViewBoundColumnBase.set_DataMemberBinding(Binding value) in c:\TB\105\WPF_Scrum\Release_SL\Sources\Development\Controls\GridView\GridView\GridView\Columns\GridViewBoundColumnBase.cs:Zeile 827.

3 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 11 Sep 2012, 12:40 PM
Hello,

 Can you post more info about your grid versions and the columns setup?

Kind regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Matthias Bibo
Top achievements
Rank 1
answered on 11 Sep 2012, 04:33 PM

The error occurs in a GridViewImageColumn. It only occurs the first time when changing the binding.
First I thought it happens in our converter (and ignored it), but then I saw the error in the designer.
We have derived all telerik controls to out own controls. "Self" is a property in our modelobject, which references to itself (to have a property for propertychanged).

<bdlControls:BDLGridViewImageColumn Header="#" DataMemberBinding="{Binding Self, Converter={StaticResource CallCenterAnrufStatusConverter}, ConverterParameter='Image'}" />


We use the "2012.2.0725.1050" version of the Telerik.Windows.Controls.GridView.dll.

Here is the complete grid:

<bdlControls:BDLGridView x:Name="gridAnrufhistorie" GroupRowStyle="{StaticResource GridViewGroupRowStyle}" Grid.Row="0" Grid.Column="0" ItemsSource="{Binding AnrufHistorieList}" SelectedItem="{Binding CurrentAnrufInHistorie, Mode=TwoWay}" AutoExpandGroups="True" CanUserFreezeColumns="False" CanUserReorderColumns="False" RowIndicatorVisibility="Collapsed" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" IsReadOnly="False" AutoGenerateColumns="False" CanUserInsertRows="False" IsFilteringAllowed="False" SelectionMode="Single" ShowGroupPanel="False">
                <bdlControls:BDLGridView.GroupDescriptors>
                    <data:GroupDescriptor Member="AnrufZielgruppe.PoolName" SortDirection="Descending">
                    </data:GroupDescriptor>
                </bdlControls:BDLGridView.GroupDescriptors>
                <bdlControls:BDLGridView.Columns>
                    <bdlControls:BDLGridViewImageColumn Header="#" DataMemberBinding="{Binding Self, Converter={StaticResource CallCenterAnrufStatusConverter}, ConverterParameter='Image'}" />
                    <bdlControls:BDLGridViewDataColumn Header="StatusWV" IsReadOnly="True">
                        <bdlControls:BDLGridViewDataColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding StatusWV}" TextAlignment="Left" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Foreground="{Binding Self, Converter={StaticResource CallCenterAnrufStatusConverter}, ConverterParameter='Foreground'}"/>
                            </DataTemplate>
                        </bdlControls:BDLGridViewDataColumn.CellTemplate>
                    </bdlControls:BDLGridViewDataColumn>
                    <bdlControls:BDLGridViewDataColumn Header="StatusAnruf" IsReadOnly="True">
                        <bdlControls:BDLGridViewDataColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding StatusAnruf}" TextAlignment="Left" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Foreground="{Binding Self, Converter={StaticResource CallCenterAnrufStatusConverter}, ConverterParameter='Foreground'}"/>
                            </DataTemplate>
                        </bdlControls:BDLGridViewDataColumn.CellTemplate>
                    </bdlControls:BDLGridViewDataColumn>
                    <bdlControls:BDLGridViewDataColumn Header="AnzeigeDatum" IsReadOnly="True">
                        <bdlControls:BDLGridViewDataColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding AnzeigeDatum}" TextAlignment="Left" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Foreground="{Binding Self, Converter={StaticResource CallCenterAnrufStatusConverter}, ConverterParameter='Foreground'}"/>
                            </DataTemplate>
                        </bdlControls:BDLGridViewDataColumn.CellTemplate>
                    </bdlControls:BDLGridViewDataColumn>
                </bdlControls:BDLGridView.Columns>
            </bdlControls:BDLGridView>










0
Matthias Bibo
Top achievements
Rank 1
answered on 11 Sep 2012, 04:45 PM
I found the issue, it comes from the converter (my fault)!
It returns null as default  (when no object is passed in) instead of value.

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
    if (value is Anruf)
    {
        switch (parameter as string)
        {
            case "Foreground":
                switch ((value as Anruf).StatusAnruf)
                {
                    case "offen":
                    case "selektiert":
                        return new SolidColorBrush(Color.FromArgb(175, 0, 100, 0));

                    case "gesperrt":
                        return new SolidColorBrush(Color.FromArgb(255, 220, 0, 0));

                    default:
                        return new SolidColorBrush(Color.FromArgb(235, 150, 20, 20));
                }

            ...
            ...            
        }
    }

    return null;   <-- This was not correct. Changing to "return value" solved the issue.
}

Tags
General Discussions
Asked by
Matthias Bibo
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Matthias Bibo
Top achievements
Rank 1
Share this question
or