how to (define and call events for a child datagrid) within the data grid
i need to define events for the datagrid with in another datagrid(master child grid) now i need to define events for child grid and call those events when i click the child data grid
i have define events for child data grid in xaml page. but these events or not getting fired. how should i开发者_运维问答 go ahead ? RowDetailsVisibilityChanged="dgrdRowDetail_RowDetailsVisibilityChanged"
is my Xaml code
<sdk:DataGrid MinHeight="100" x:Name="dgCounty" AutoGenerateColumns="False" VerticalAlignment="Top" Grid.Row="1" IsReadOnly="True" Margin="5,5,5,0" RowDetailsVisibilityChanged="dgCounty_RowDetailsVisibilityChanged" SelectionMode="Extended" RowDetailsVisibilityMode="VisibleWhenSelected">
<sdk:DataGrid.Columns>
<sdk:DataGridTemplateColumn>
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button x:Name="myButton" Width="24" Height="24" Click="Details_Click">
<Image x:Name="img" Source="Images/detail.JPG" Stretch="None"/>
</Button>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
<sdk:DataGridTemplateColumn Header="ID">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate >
<sdk:Label Content="{Binding EmployeeID}" />
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
<sdk:DataGridTemplateColumn Header="Name">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate >
<sdk:Label Content="{Binding EmployeeFName}" />
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
<sdk:DataGridTemplateColumn Header="MailID">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate >
<sdk:Label Content="{Binding EmployeeMailID}" />
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
</sdk:DataGrid.Columns>
<sdk:DataGrid.RowDetailsTemplate>
<DataTemplate>
<sdk:DataGrid x:Name="dgrdRowDetail" Width="400" HeadersVisibility ="None" AutoGenerateColumns="False" HorizontalAlignment="Center" IsReadOnly="True" RowDetailsVisibilityChanged="dgrdRowDetail_RowDetailsVisibilityChanged" SelectionMode="Extended" RowDetailsVisibilityMode="VisibleWhenSelected">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Binding="{Binding CompanyName}"/>
<sdk:DataGridTextColumn Binding="{Binding CompanyID}"/>
<sdk:DataGridTemplateColumn Header="Score">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate >
<StackPanel Loaded ="StackPanel_Loaded" Orientation="Horizontal" Background="Transparent">
<TextBlock Text="{Binding Score}" TextWrapping="NoWrap" HorizontalAlignment="Center" Foreground="Blue"></TextBlock>
<Image x:Name="imgScore" Source ="{Binding Score}" Width="20" Height="20" Stretch ="Fill"/>
</StackPanel>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
</sdk:DataGrid.Columns>
</sdk:DataGrid>
</DataTemplate>
</sdk:DataGrid.RowDetailsTemplate>
</sdk:DataGrid>
private void dgrdRowDetail_RowDetailsVisibilityChanged(object sender, DataGridRowDetailsEventArgs e)
{
}
does any one knows how to define and call the events of child datagrid. any help would be great looking frwd for an solution.
thanks in advance
prince
Soution: define globally DataGrid dgrdRowDetail;
in event parent event we can fine the child data grid and then define the event for the child data grid to.
private void dgCounty_RowDetailsVisibilityChanged(object sender, DataGridRowDetailsEventArgs e)
{
dgrdRowDetail = (DataGrid)e.DetailsElement.FindName("dgrdRowDetail");
dgrdRowDetail.RowDetailsVisibilityChanged+=new EventHandler<DataGridRowDetailsEventArgs>(dgrdRowDetail_RowDetailsVisibilityChanged);
}
once you get your dgrdRowDetail which is the child control then yoy can perform all the actions against it like binding,events all those stuff.
精彩评论