按钮未在DataGridRow详细信息

时间:2018-04-12 07:20:46

标签: c# wpf

我有一个数据网格,单击datagridrow,需要在行下面显示动态按钮详细信息。但是按钮单击对我不起作用。

我在下面添加了代码段。

在用户控制资源中

<DataTemplate x:Key="rowDT" >
            <StackPanel Loaded="StackPanel_Loaded" Orientation="Horizontal" 
                        Height="50" HorizontalAlignment="Center"  VerticalAlignment="Stretch" >

            </StackPanel>
        </DataTemplate>

Datagrid xaml详细信息

<DataGrid Name="dgUsers" ItemsSource="{Binding Interactions,RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}" Grid.Row="1" AutoGenerateColumns="False"  CanUserAddRows="false" IsReadOnly="True" Background="White" RowStyle="{StaticResource DataGridRowStyle}" ColumnHeaderStyle="{StaticResource DataGridColumnHeaderStyle}" >
                            <DataGrid.Columns >
                                <DataGridTextColumn Header="QUEUE" Binding="{Binding Queue}" Width="100"  />
   </DataGrid.Columns>
  </DataGrid>

我在构造函数

后面编码
var rowDetailsTemplate = (DataTemplate)this.Resources["rowDT"];
dgUsers.RowDetailsTemplate= rowDetailsTemplate;

并且在堆栈面板加载的事件中我正在加载我的按钮

private void StackPanel_Loaded(object sender, RoutedEventArgs e)
        {
            StackPanel templateChildPanel = sender as StackPanel;
 Button InteractionViewButton = new Button
            {
                Width = 150,
                Height = 30,
                Content = "VIEW CALL DETAILS",
                Style = this.FindResource("RegularButton") as Style,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center            

        };
  InteractionViewButton.Click += new RoutedEventHandler(InteractionViewButton_Click);
templateChildPanel.Children.Add(InteractionViewButton );               
                }

但按钮点击没有解雇?怎么解决这个问题?

0 个答案:

没有答案