Is it possible to bind the current item to a tag in button from a listview itemsource like this. How do i do it Please help
<ListView ItemsSource="Assignments">
<ListView.ItemTemplate>
<DataTemplate>
<Button Tag="{Binding CurrentItem}">
</Button>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Yes, if Assignments is a collection of string then you need
<Button Tag="{Binding}">
If Assignments is a collection of Assignment where Assignment has a property Name you need
<Button Tag="{Binding Name}">
If by "current item" you mean the currently selected item:
<Button Tag="{Binding SelectedItem, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListView}}}"/>
If by "current item" you mean the data item being rendered by the template:
<Button Tag="{Binding}"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With