简体   繁体   中英

Binding of command parameter with Element value of a datagrid

Iam Trying to Bind "Description" column value of dataGrid to command parameter of a button inside same grid row but, Binding not working properly. code:-

   <DataGrid x:Name="devicelist" Background="SkyBlue" AutoGenerateColumns="False"  ItemsSource="{Binding Path=DeviceList}" SelectionChanged="devicelist_SelectionChanged"  >
 <DataGrid.Columns>  
                <!--Description-->
                <DataGridTextColumn Header="Descrition" Width="*"  IsReadOnly="True" Binding="{Binding Path=Description}">
                </DataGridTextColumn>                         
                          
                <!--testcaseSelection button-->
                <DataGridTemplateColumn Header="TestCases" Width="*" >
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Button Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType= {x:Type Window}}, 
                             Path=DataContext.CurrentViewModel.SelectTestCommand}" CommandParameter="{Binding Path=Description}" >TestCases</Button>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
 </DataGrid.Columns>
</DataGrid>

the command that i have binded is working properly and getting called also.

As explained here , try to declare the CommandParameter before the Command :

<Button CommandParameter="{Binding Path=Description}"
        Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType= {x:Type Window}}, 
                          Path=DataContext.CurrentViewModel.SelectTestCommand}"
        Content="TestCases" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM