Below is a simple sample application itemTemplate checkbox is a command binding that is causing the problem. When I try to run it, I get a NullReferenceException (Microsoft Practice .compos. Presentation Commands.Delit Commands 1. Systems.indows.insut.ICComxActext ...). Why does this happen
Main window. Xml:
& lt; Window x: orbit = "checkbox comtat.manvindo" xmlns = "http://schemas.microsoft.com/enfx/ 2006/xaml/presentation" xmlns: x = "http://schemas.microsoft.com/winfx/2006 / Xaml "datacontext =" {binding relative saras = {relative escrows}} "& gt; & Lt; StackPanel x: name = "stackpanel" & gt; & Lt; ItemsControl ItemSource = "{Bound Checkbox}" & gt; & Lt; ItemsControl.ItemTemplate & gt; & Lt; DataTemplate & gt; & Lt; Checkbox content = "{binding name}" IsChecked = "{Binding IsSelected}" command = "{binding data contents. Checkbook comand, elementname = stackpanyell}" commandpamator = "{binding parameter}" Lt; / DataTemplate & gt; & Lt; /ItemsControl.ItemTemplate> & Lt; / ItemsControl> & Lt; / StackPanel & gt; & Lt; / Window & gt; MainWindow.xaml.cs
Public Partial Class Home Window: Window, INotifyPropertyChanged {Public MainWindow () {InitializeComponent (); Checkbox comand = new representative column & lt; Int & gt; (OnCheckBoxChecked); Checkbox = new list & amp; CheckboxModel & gt; () {New checkbox model {name = "checkbox # 1", parameter = 1}, new checkbox model {name = "checkbox # 2", parameter = 2},}; TriggerPropertyChanged ("Check Box"); } Public listing & lt; CheckboxModel & gt; Checkbox {receive; Set; } Public ICMMand Checkbox Commands {Received; Set; } Private Zero onCheckBoxChecked (int i) {/ * Nothing} /}} CheckboxModel. Cs
public class checkbox modell {public string name {get; Set; } Public Bull ISEelected {get; Set; } Receive public AT parameters { Set; }}
This is likely to be the most likely because you can specify your command parameters, parameters With the binding for. When the template is first loaded, the binding is not yet evaluated, so at the beginning of the commandpayer property (type object ) (and only temporarily) a null Value is assigned. When it is bound (in this case right before CommandParameter), then the delegation command then tries to use the zeros parameter as a int , the parameter is a reference type, but clearly Type is invalid for the value like int You may be able to correct the error by changing the parameter type and correcting the code in your command handlers
Comments
Post a Comment