【发布时间】:2012-08-24 04:01:23
【问题描述】:
我有一个DataGrid 显示在 XAML 中定义的客户列表,如下绑定到我的 ViewModel:
<DataGrid Name="CustomersDataGrid" ItemsSource="{Binding Customers}">
<DataGrid.Columns>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Command="{Binding showCustomerCommand}"
Content="{Binding Path=Name}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
网格的显示工作正常。我希望能够显示单个客户的详细信息。以前,我为所选行设置了绑定,并在页面上有一个按钮,该按钮绑定到以下命令:
RelayCommand _showCustomerCommand;
public ICommand showCustomerCommand
{
get
{
if (_showCustomerCommand == null)
{
_showCustomerCommand = new RelayCommand(param => this.ShowCustomer());
}
return _showCustomerCommand;
}
}
private void ShowCustomer()
{
if (Parent != null)
{
// Handle Customer Display Here
}
}
这很好用。但我希望能够单击单个行内的按钮,而不是基于选定行的单个按钮。我知道上述 XAML 中的数据上下文是错误的,但我不知道如何纠正它,也不知道如何传递按钮按下的特定行。任何和所有帮助我连接嵌入式按钮的建议都非常感谢!
【问题讨论】:
-
嘿,我知道我在这里有点挖坟,但是您找到解决这种情况的方法了吗?我正在尝试完成同样的事情。