This is a migrated thread and some comments may be shown as answers.

How to Get Mouse Position on Context Menu Command(MVVM)

1 Answer 341 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Semih
Top achievements
Rank 1
Semih asked on 16 Dec 2014, 06:56 AM
Hi,

I'm using MVVM pattern on Diagram. I have a context menu set inside a style for targettype RadDiagramContainerShape. I want to pass the mouse position to the command as parameter (inside "NewShapeMenuItem" MenuItem).

How can I achieve this?

        <Style TargetType="telerik:RadDiagramContainerShape">            
            <Setter Property="ContextMenu">
                <Setter.Value>
                    <ContextMenu Name="ComponentContextMenu">
                        <MenuItem Name="NewMenuItem" Header="New">
                            <MenuItem Name="NewShapeMenuItem" Header="Shape" Command="{Binding AddCommand}" CommandParameter="{Binding ElementName=StateDiagram, Path=ActualHeight}" Icon="{StaticResource GoToShapeImage}"/>
                        </MenuItem>
                        <Separator/>
                        <MenuItem Header="Go to State" ItemsSource="{Binding ParentFacility.SelectedComponentViewModel.StateViewModels}"><!--IsEnabled="{Binding ParentFacility.Parent.IsOnline, Mode=TwoWay}"-->
                            <MenuItem.IsEnabled>
                                <MultiBinding Converter="{StaticResource ComponentToIsEnabledConverter}" Mode="TwoWay">
                                    <Binding Path="ParentFacility.Parent.IsOnline" Mode="TwoWay"/>
                                    <Binding Path="ParentFacility.SelectedComponentViewModel"/>
                                </MultiBinding>
                            </MenuItem.IsEnabled>
                            <MenuItem.ItemContainerStyle>
                                <Style TargetType="MenuItem">
                                    <Setter Property="Icon" Value="{StaticResource GoToStateImage}"></Setter>
                                    <Setter Property="Header" Value="{Binding Name}"></Setter>
                                    <Setter Property="Command" Value="{Binding ParentComponent.ParentFacility.GoToStateCommand}"></Setter>
                                    <Setter Property="CommandParameter" Value="{Binding}"></Setter>
                                </Style>
                            </MenuItem.ItemContainerStyle>
                        </MenuItem>
                    </ContextMenu>
                </Setter.Value>
            </Setter>
        </Style>

1 Answer, 1 is accepted

Sort by
0
Pavel R. Pavlov
Telerik team
answered on 18 Dec 2014, 04:01 PM
Hi Semih,

When working with ContextMenu you need to keep in mind that it actually is in different visual tree. This is why the DataContexts are also different and there is no easy way to gain access to the container which the user has clicked (in order to calculate the mouse position). 

You can take a look at our documentation for more information.

Regards,
Pavel R. Pavlov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Diagram
Asked by
Semih
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
Share this question
or