2012-07-27 46 views
1

假設我有如下的XAML標記。如何將按鈕的命令參數綁定到每一行。請顯示最合適的綁定表達式。綁定gridview行上的每個項目

<ListView ItemsSource="{Binding Items}"> 
    <ListView.View> 
    <GridView> 
     <GridViewColumn Header="Items" Width="Auto"> 
     <GridViewColumn.CellTemplate> 
      <DataTemplate> 
      <TextBlock Text="{Binding Path=Name, Mode=OneWay}"/> 
      </DataTemplate> 
     </GridViewColumn.CellTemplate> 
     </GridViewColumn> 
    <GridViewColumn Header="" Width="Auto"> 
     <GridViewColumn.CellTemplate> 
     <DataTemplate> 
      <Button MinWidth="100" Command="{Binding DeleteCommand}" CommandParameter="{Binding <EXPRESSION>}" >Delete</Button> 
     </DataTemplate> 
     </GridViewColumn.CellTemplate> 
    </GridViewColumn> 
    <ListView.View> 
</ListView> 
+0

哪裏XAML? – 2012-07-27 21:21:20

+0

格式化了xml – TrustyCoder 2012-07-27 21:25:07

回答

1

這是有效的。

CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type GridViewRowPresenter}}, Path=DataContext}" 
0

我討厭WPF。

創建一個自我指涉的財產

這個屬性添加到您綁定的數據模型類:

public class MyDataObjectItem 
{ 
    //... 
    public MyDataObjectItem Self { get { return this; } } 
    //... 
} 

然後命令參數很簡單:

CommandParameter="{Binding Self}" 

或者,顯然此作品

CommandParameter="{Binding}" 

看到https://stackoverflow.com/a/11287478/887092

相關問題