我是 wpf mvvm 的新手。为了在选择时从数据网格中获取值,我创建了一个对象数据类型的属性。当我单击数据网格行时,我得到一组包含名字、姓氏、城市、州的值,pin,mobileno,mail id,employee id 等。我需要从中检索员工 id 用于更新目的..但我不知道如何从对象数据类型中声明的属性中检索这些值..请帮助我.. ..\
这是我的视图模型
public object selectedEmployee;
public object SelectedEmployee
{
get
{
return selectedEmployee;
}
set
{
selectedEmployee = value;
OnPropertyChanged("SelectedEmployee");
}
}
这是我的 xaml 代码
<DataGrid Grid.Row="2" x:Name="grdEmployee" SelectedItem="{Binding SelectedEmployee, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" ItemsSource="{Binding EmployeeDatatable, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=True}" AutoGenerateColumns="False" IsReadOnly="True" HorizontalAlignment="Center" Margin="59,0,86,12" Width="492" CanUserAddRows="False"
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Emp_id}" Header="Employee ID"></DataGridTextColumn>
<DataGridTextColumn Binding="{Binding FirstName}" Header="FirstName"></DataGridTextColumn>
<DataGridTextColumn Binding="{Binding LastName}" Header="LastName"></DataGridTextColumn>
<DataGridTextColumn Binding="{Binding Age}" Header="Age"></DataGridTextColumn>
<DataGridTextColumn Binding="{Binding ZipCode}" Header="ZipCode"></DataGridTextColumn>
<DataGridTextColumn Binding="{Binding PhoneNumber}" Header="PhoneNumber"></DataGridTextColumn>
<DataGridTextColumn Binding="{Binding MobileNumber}" Header="MobileNumber"></DataGridTextColumn>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Name="btnEdit" Content="Edit"></Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>