i have a datagrid declared in the xaml as follows:
<sdk:DataGrid x:Name="ProductsForProjectDataGrid" AutoGenerateColumns="True" ItemsSource="{Binding Path=Products.ProductsForProject}">
<sdk:DataGrid.Columns>
<sdk:DataGridTemplateColumn x:Name="DeleteTemplate" Width="10*">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button x:Name="DeleteProductButton" Command="{Binding DeleteProductCommand}" CommandParameter="Products.SelectedProduct" >
<Button.Content>
<Image x:Name="DeleteProductImage" Visibility="Visible" Height="20" Source="C:\Documents and Settings\DELETE.GIF" Width="20"/>
</Button.Content>
</Button>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
<sdk:DataGridTextColumn Binding="{Binding Product}" Header="Product Name" IsReadOnly="True" Width="40*"/>
</sdk:DataGrid.Columns>
</sdk:DataGrid>
and in the viewModel i’ve to link the button to a command, i can get the reference to the datagrid using this,
_dlgProducts.ProductsForProjectDataGrid
where _dlgproducts is the object,
now how can i get a reference to the delete button,
once i get the reference i can bind a command to it,
i need something like
_dlgProducts.ProductsForProjectDataGrid.DeleteProductButton
or something, im not sure how to get it…
Thanks 🙂
Binding inside
DataTemplateinDataGridin Silverlight doesn’t work as you would expect. You need to useDataContextProxy. See sample here:http://weblogs.asp.net/dwahlin/archive/2009/08/20/creating-a-silverlight-datacontext-proxy-to-simplify-data-binding-in-nested-controls.aspx