简体   繁体   English

命令参数与数据网格的元素值的绑定

[英]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.我正在尝试将 dataGrid 的“描述”列值绑定到同一网格行内按钮的命令参数,但是绑定无法正常工作。 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 :如此所述,尝试在Command之前声明CommandParameter

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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