I have a list view, where I wanted to Hide ContextMenuItems based on some value in the ListView Column. I could achieve this by moving ContextMenu to ListView.ItemContainerStyle. Now my problem is that I am unable to fire Commands on MenuItem. This used to work when ContextMenu was set directly to ListView.
Here is what I have tried and failed. (Used ElementType, ElementName, Direct call etc.).
 <UserControl Name="RootElement" DataContext=.Some Context.....>     
 <ListView ItemsSource="{Binding LicensesView}">
                <ListView.ItemContainerStyle>
                    <Style TargetType="{x:Type ListViewItem}">
                        <Setter Property="ContextMenu">
                            <Setter.Value>
                                <ContextMenu>
                                    <MenuItem Header="Refresh 1" Command="{Binding Path=DataContext.LicenseListRefreshCommand, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" />
                                    <MenuItem Header="Refresg 2" Command="{Binding Path=DataContext.LicenseListRefreshCommand, RelativeSource={RelativeSource AncestorType=Window, Mode=FindAncestor}}"/>
                                    <MenuItem Header="Refresh 3" Command="{Binding Path= DataContext.LicenseListRefreshCommand, ElementName=RootElement}" Visibility="{Binding Path=Aktif,Converter= {StaticResource BoolToVisibility}}"/>
                                    <MenuItem Header="Refresh 4" Command="{Binding LicenseListRefreshCommand}"/>
                                </ContextMenu>
                            </Setter.Value>                           
                        </Setter>
                  </Style>
                </ListView.ItemContainerStyle>
                <ListView.View>
                    <GridView>
                        <GridViewColumn Header="Code" DisplayMemberBinding="{Binding Code}" Width="Auto"/>
                        <GridViewColumn Header="Active" DisplayMemberBinding="{Binding Active}" Width="150" />
                        <GridViewColumn Header="Company" DisplayMemberBinding="{Binding Company}" Width="60" />
                        <GridViewColumn Header="Demo" DisplayMemberBinding="{Binding Demo}" Width="Auto" />
                    </GridView>
                </ListView.View>
            </ListView>
</UserControl>
