Hi,
I am developing a WPF application in which I need to call MouseLeftButtonDown
event in a single DataGridTextColumn
.
For that I wrote some xaml code as :-
<DataGridTextColumn x:Name="myAge" Header="Age" Binding="{Binding Age, Mode=TwoWay}" IsReadOnly="True" Width="*">
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell">
<EventSetter Event="MouseLeftButtonDown" Handler="{Binding MyAgeCommand}" />
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
But I am getting an "Object reference null" exception. I tried searching this over the Internet however all I found a solution in which I need to refer to an external AttachedCommandBehavior.dll
but I don't want to do this.
All I need to ask is some way so that I can bind my Handler
to MyAgeCommand
as persently, I am unable to do that.
My ViewModel is :-
public DelegateCommand MyAgeCommand
{
get
{
if (_myAgeCommand == null)
_myAgeCommand = new DelegateCommand(MySelectedCell);
return _myAgeCommand;
}
}
private void MySelectedCell(object obj)
{
// Rest of the code
}