c# - Migrating to .Net 4: Null reference exceptions thrown when adding event in xaml -


In place of my work, we recently upgraded our codebase from .NET 3.5 to .NET 4 (C #). Have given. Most issues have been solved, but this one I can not understand. We begin with the controls and pages through the mix based on XML and code-behind (developer preference), but throws a page NullReferenceException when opening here is a snippet of code (a lot of control

throwing all code exceptions is inside a datatomplate ( I thought it might be relevant ) Pre> & lt; TextBox x: Name = "value" Grid.Column = "1" Grid.Row = "0" Margin = "5,2,5,2" Text = "{Binding ElementName = statement path = SelectedValue, UpdateSourceTrigger = PropertyChanged mode = TwoWay, Converter = {StaticResource EmptyConverter}} "GotFocus =" Column_GotFocus "MinWidth =" 100 "CharacterCasing =" top "visibility =" {binding path = IsValueVisible, Converter = {StaticResource VisibilityConverter}} "/ & gt; The

Now in this, throw line:

  GotFocus = "Column_GotFocus"   

In Column_GotFocus file Back to the code Some other facts: We had no problems before migration, the exception throws continuously, and due to this problem there are three separate incidents.

are throwing three events:

  GotFocus = "Column_GotFocus" SelectionChanged = click = "Search_Click"   problems with functional software 

Our reforms are being completely resolved, but obviously the "Descriptions_SelectionChanged" causes these improvements. Does anyone know what can happen due to these issues?

Edit:

Sorry, to clarify: Event handler is never called, add xaml event handler (for example GotFocus = "Column_GotFocus") seems to be where the exception is thrown.

The exception is:

  System.NullReferenceException occurred Message = object reference is not set to an instance of an object Source = & lt; Assembly / Namespace & gt; StackTrace: & lt; Assembly / Namespace & gt; & Lt; Class & gt; .ystem in Windows.Markup.IStyleConnector.Connect (Int32 connectionId, object target) & lt; XamlFilePath & gt ;: line 291 Inner Akspasn:   

Edit 2:

method handler:

  Private Zero Column_GotFocus (Object Sender, RoutedEventArgs E) {ContentPresenter columnContentPresenter = (DependencyObject) Sender) .FindParent & LT; ContentPresenter & gt; (); Column column = (column) column conference viewer. material; String message = string Format ("{0} ({1})", column name, column.field); ModuleDescriptor.UpdateStatusBar (message); }    

I think you are a problem, you are trying to add event handlers. A style setter key = "YourSyleName" TargetType = "{:; style x

  & lt: this (for unclear reasons) ... You should use EventSetters instead  

is forbidden for example X: type CtrlType} "& gt; & Lt; EventSetter Event = "PreviewMouse Left BootDowndown" Handler = "dgClient_PreviewMouseLeftButtonDown" /> & Lt; EventSetter Event = "Loaded" Handler = "Grid Content_loaded" /> & Lt; / Style & gt;

Comments