I have a ListView showing a list of Accounts using MVVM & a custom template and working fine
Now on clicking the Acct Name, we need to execute a custom action which requires the current Acct object
Is there a way to set the Label.Tag property to the Acct object ?
the xaml def is below
env is vs2010 .net 4.0 c#
<ListView Name="lv1" Grid.Column="1" Grid.Row="4"
ItemsSource="{Binding AccountsList}"
Background="Transparent" BorderThickness="0">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="/asm1;component/Images/Icons/pdf1.png" Width="12" Height="12" />
<Label Content="{Binding Name}" Margin="0,0,25,0"
ContextMenu="{x:Null}" Name="lblacctItem"
MouseDoubleClick="lbl_MouseDoubleClick" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Background="Transparent"
Width="{Binding (FrameworkElement.ActualWidth), RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}"
ItemWidth="{Binding (ListView.View).ItemWidth, RelativeSource={RelativeSource AncestorType=ListView}}"
MinWidth="{Binding ItemWidth, RelativeSource={RelativeSource Self}}"
ItemHeight="{Binding (ListView.View).ItemHeight, RelativeSource={RelativeSource AncestorType=ListView}}" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
You are mixing MVVM and code behind.
You should create a command behavior (Link) to label. Then you should bind CommandParameter to AccObject, and Command to the action you need to execute.
Following should be removed.
Updated as per comments
As current item is bound to AccObject, simply use Binding in command parameter.