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

Null pointer exception when trying to add event handler

4 Answers 52 Views
GridView
This is a migrated thread and some comments may be shown as answers.
asp.net
Top achievements
Rank 1
asp.net asked on 07 Aug 2012, 03:13 PM
My application is crashing when I am opening a window with a grid having a templated cell. The markup for the cell is given below. The app works fine if I do not add this event handler Initialized=btnNoActionRequired_Initialized (or any event handler) for the RadButton. It starts carshing when I add any event handler. The stack trace is given at the end of this message. Please help.  Thanks!

Cell Template

<Style TargetType="telerik:GridViewCell">
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="telerik:GridViewCell">
                                            <Grid VerticalAlignment="Center">
                                                <TextBlock Text="{Binding Path='', Converter={StaticResource ItemActionText}}" Margin="5,0,0,0"></TextBlock>
                                                <StackPanel Orientation="Horizontal" Visibility="{Binding Path='', Converter={StaticResource ItemButtons}}">
                                                    <telerik:RadButton Background="{StaticResource BgGreen}" Width="100" Height="40" Margin="5,0,5,0" Tag="T" CommandParameter="{Binding Path=''}" Name="btnNoActionRequired" Initialized="btnNoActionRequired_Initialized">
                                                        <TextBlock Text="Checked, No Action Required" TextWrapping="Wrap" TextAlignment="Center"></TextBlock>
                                                    </telerik:RadButton>
                                                    <telerik:RadButton Background="{StaticResource BgRed}" Foreground="{StaticResource FgLighGrey}"   Width="100" Height="40" Margin="0,0,5,0" Tag="S" CommandParameter="{Binding Path=''}">
                                                        <TextBlock Text="Safety Related" TextWrapping="Wrap" TextAlignment="Center"></TextBlock>
                                                    </telerik:RadButton>
                                                    <telerik:RadButton Background="{StaticResource BgOrange}" Foreground="{StaticResource FgLighGrey}" Width="100" Height="40" Margin="0,0,5,0" Tag="G" CommandParameter="{Binding Path=''}">
                                                        <TextBlock Text="General Repair" TextWrapping="Wrap" TextAlignment="Center"></TextBlock>
                                                    </telerik:RadButton>
                                                    <telerik:RadButton Background="{StaticResource BgOrange}" Foreground="{StaticResource FgLighGrey}" Width="100" Height="40" Margin="0,0,5,0" Tag="M" CommandParameter="{Binding Path=''}">
                                                        <TextBlock Text="Minor Defect Monitor Item" TextWrapping="Wrap" TextAlignment="Center"></TextBlock>
                                                    </telerik:RadButton>
                                                    <telerik:RadButton Background="{StaticResource BgGrey}" Foreground="{StaticResource FgDarkGrey}"  Width="100" Height="40" Margin="0,0,5,0" Tag="X"  CommandParameter="{Binding Path=''}">
                                                        <TextBlock Text="Not Applicable" TextWrapping="Wrap" TextAlignment="Center"></TextBlock>
                                                    </telerik:RadButton>
                                                </StackPanel>
                                            </Grid>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>

Stack Trace  

at Dealerpoint.ServicePack.WPF.ServiceForm.System.Windows.Markup.IStyleConnector.Connect(Int32 connectionId, Object target) in c:\SL\Dealerpoint.ServicePack.WPF\Dealerpoint.ServicePack.WPF\ServiceForm.xaml:line 65
   at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter)
   at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlObjectWriter objectWriter)
   at System.Windows.FrameworkTemplate.LoadOptimizedTemplateContent(DependencyObject container, IComponentConnector componentConnector, IStyleConnector styleConnector, List`1 affectedChildren, UncommonField`1 templatedNonFeChildrenField)
   at System.Windows.FrameworkTemplate.LoadContent(DependencyObject container, List`1 affectedChildren)
   at System.Windows.StyleHelper.ApplyTemplateContent(UncommonField`1 dataField, DependencyObject container, FrameworkElementFactory templateRoot, Int32 lastChildIndex, HybridDictionary childIndexFromChildID, FrameworkTemplate frameworkTemplate)
   at System.Windows.FrameworkTemplate.ApplyTemplateContent(UncommonField`1 templateDataField, FrameworkElement container)
   at System.Windows.FrameworkElement.ApplyTemplate()
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.ContextLayoutManager.UpdateLayout()
   at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
   at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()
   at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
   at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
   at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
   at System.Threading.ExecutionContext.runTryCode(Object userData)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run(Window window)
   at System.Windows.Application.Run()
   at Dealerpoint.ServicePack.WPF.App.Main() in C:\SL\Dealerpoint.ServicePack.WPF\Dealerpoint.ServicePack.WPF\obj\x86\Debug\App.g.cs:line 0
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

4 Answers, 1 is accepted

Sort by
0
asp.net
Top achievements
Rank 1
answered on 09 Aug 2012, 09:52 AM
Any pointers on what could be going wrong..
0
asp.net
Top achievements
Rank 1
answered on 10 Aug 2012, 03:14 PM
Been three days, anyone from the support care to reply please?
0
Vlad
Telerik team
answered on 13 Aug 2012, 05:48 AM
Hi,

 Our forums are community resources and if you want to contact Telerik support you can open support ticket.

Adding event handlers in style setters is not supported in WPF - you can check this thread for more info:
http://stackoverflow.com/questions/11411642/migrating-to-net-4-null-reference-exceptions-thrown-when-adding-event-in-xaml 
 

Greetings,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
asp.net
Top achievements
Rank 1
answered on 13 Aug 2012, 02:55 PM
Thank you very much. I am to able to get it work now.
Tags
GridView
Asked by
asp.net
Top achievements
Rank 1
Answers by
asp.net
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or