我在ObservableCollection<MembershipUserProfiled>
元素上绑定了此项目模板,因此可以在ListBox
中显示。
<UserControl.Resources>
<ResourceDictionary>
<DataTemplate x:Key="ListItemElencoTemplate">
<Grid Background="#FFFFFF" Width="300">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="110" />
<ColumnDefinition Width="110" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="20" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Style="{DynamicResource label_default}" HorizontalContentAlignment="Left" VerticalContentAlignment="Center" Content="{Binding Path=FirstName}" Margin="0 0 0 3" />
<Label Grid.Column="1" Style="{DynamicResource label_default}" HorizontalContentAlignment="Left" VerticalContentAlignment="Center" Content="{Binding Path=LastName}" Margin="0 0 0 3" />
<Label Grid.Column="2" Style="{DynamicResource label_default}" HorizontalContentAlignment="Left" VerticalContentAlignment="Center" Content="{Binding Path=BaseUser.UserName}" Margin="0 0 0 3" />
<Button Content="Button" Style="{DynamicResource edit}" Click="Edit_Click" CommandParameter="{Binding Path=...}" HorizontalAlignment="Right" Grid.Column="4" Width="20" Height="20"/>
</Grid>
</DataTemplate>
</ResourceDictionary>
</UserControl.Resources>
一切正常但我想将按钮CommandParameter
绑定到行的MembershipUserProfiled
对象,以便传递点击操作的数据。
我尝试了不同的解决方案,但似乎没有任何效果。我想做的是可行的吗?
答案 0 :(得分:1)
您可以尝试CommandParameter =“{Binding}”这将自动绑定MembershipUserProfiled对象
<Button Content="Button" CommandParameter="{Binding}" Style="{DynamicResource edit}" Click="Edit_Click" HorizontalAlignment="Right" Grid.Column="4" Width="20" Height="20"/>