我有以下XAML
<Window.Resources>
<DataTemplate x:Key="SelectButtonColumnDataTemplate">
<Button Content="Select" Command="{Binding SelectItemCommand}" Click="SelectButtonClick" />
</DataTemplate>
</Window.Resources>
<Grid x:Name="LayoutRoot">
<ListView x:Name="listFeedSearch" HorizontalAlignment="Left" Width="542.5" RenderTransformOrigin="0.5,0.5" ItemsSource="{Binding SearchCollection}">
<ListView.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</ListView.RenderTransform>
<ListView.View>
<GridView>
<GridViewColumn Width="150" Header="Feed Name" x:Name="listFeedSearchName" DisplayMemberBinding="{Binding FeedName}" />
<GridViewColumn Width="280" Header="Feed Address" x:Name="listFeedSearchAddress" DisplayMemberBinding="{Binding FeedUrl}" />
<GridViewColumn Width="100" Header=" " CellTemplate="{StaticResource SelectButtonColumnDataTemplate}" />
</GridView>
</ListView.View>
</ListView>
</Grid>
添加以下事件处理程序:
private void SelectButtonClick(object sender, RoutedEventArgs e)
{
}
我想做的是输出行的单个绑定值。
我该怎么做,我知道这是一个类似的东西
var data = (sender as Button)...
感谢
如果您将CommandParameter按钮设置为(感谢Bolu(:
"{Binding}"
那么下面的代码将检索当前单击的对象并显示一个消息框。其中,foo是用于填充gridview 的类
public class foo
{
string FeedName {get;set;}
string FeedUrl {get;set;}
}
public void InitialiseListView(List<Foo> Items)
{
listFeedSearch.ItemsSource = Items;
}
private void SelectButtonClick(object sender, RoutedEventArgs e)
{
foo b = (foo)(sender as Button).CommandParameter;
string s = string.format("Name: {0} URL: {1}",b.FeedName,b.FeedUrl);
MessageBox.Show(s);
}
如果我理解正确,您需要使用{Binding}
:Xaml:Binding到当前DataContext
参考:理解WPF绑定命令参数=";{绑定}";