tags:

views:

16

answers:

0

I have to generate a contextMenu. it is diferent depending of which column is selected. the number of columns is diferent any time.

I have this code

<Grid x:Name="LayoutRoot" Background="White">
    <ListView Name="myListview" ItemContainerStyle="{StaticResource style1}" DockPanel.Dock="Left" ItemsSource="{Binding lsts}"  >
    </ListView>
</Grid>

where style1 is

 <Style x:Key="style1" TargetType="ListViewItem">
        <EventSetter Event="ContextMenu.ContextMenuOpening" Handler="OnMenuOpen" HandledEventsToo="True"></EventSetter>
        <Setter Property="ListViewItem.ContextMenu">
            <Setter.Value>
                <StaticResourceExtension ResourceKey="cmenu"></StaticResourceExtension>
            </Setter.Value>
        </Setter>
        <Style.Resources>

        </Style.Resources>
    </Style>

the event goes to this event handler

       void OnMenuOpen(object sender, ContextMenuEventArgs e)
        {
            ListViewItem lvi = sender as ListViewItem;
            ContextMenu cm = lvi.ContextMenu;
            cm.Items.Clear();

            List<String> myList = (List<String>) lvi.DataContext;
            String accountName = myList[0];

           .......
        }

Like this, I got the row that was clicked, but How can I get the column. I don't like the idea of checking the x,y. I can't believe that is the only way.

any help will be appretiated.

Thanks