我是WPF的新手。我將數據表綁定到我的wpf項目中的數據網格。我有我的DataGrid中的按鈕和按鈕單擊事件,我試圖找到GridViewRow。但是我將Grdrow1視爲null。GridViewRow在DataGrid中爲空
我的代碼:
<my:DataGrid Name="GridView1" ItemsSource="{Binding}" AutoGenerateColumns="False" >
<my:DataGrid.Columns>
<my:DataGridTemplateColumn Header="Vehicle Reg. No." Width="SizeToCells">
<my:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Name="btnUserId" Cursor="Hand" Click="btnUserId_Click" Content="{Binding Path=VehicleReg }" Style="{StaticResource LinkButton}"></Button>
</DataTemplate>
</my:DataGridTemplateColumn.CellTemplate>
</my:DataGridTemplateColumn>
<my:DataGridTextColumn Header="Vehicle Name" Binding="{Binding Path=VehicleName}">
</my:DataGridTextColumn>
</my:DataGrid.Columns>
</my:DataGrid>
我的C#代碼是:
private void btnUserId_Click(object sender, RoutedEventArgs e)
{
GridViewRow Grdrow1 = ((FrameworkElement)sender).DataContext as GridViewRow;
}
-------我的後期編輯------
我有使用GridViewRow的命名空間下面: -
using System.Web.UI.WebControls;
這是當前或任何其他我必須使用?
如何將數據綁定到'DataGrid'? –