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

ContextMenu for RadPane

1 Answer 175 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
Karandeep Singh
Top achievements
Rank 1
Karandeep Singh asked on 07 Sep 2012, 10:56 PM
I am trying to pass the sender (control i.e. a Radpane from where the context menu was invoked) as command parameter.

The code is as follows:

<Window.DataContext>
    <ViewModel:MainWindowViewModel x:Name="ViewModelContext">
        <ViewModel:MainWindowViewModel.ContextMenuTemplate>
            <DataTemplate >
                <tel:RadContextMenu>
                    <tel:RadMenuItem Header="Floating"
                                           Command="tel:RadDockingCommands.Floating" />
                    <tel:RadMenuItem Header="Dockable"
                                           Command="tel:RadDockingCommands.Dockable" />
                    <tel:RadMenuItem Header="Save"
                                            Command="{Binding Save}"/>
                    <tel:RadMenuItem Header="Close"
                                            Command="{Binding Close}"
                                            CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type tel:RadPane}}}"  />
                </tel:RadContextMenu>
            </DataTemplate>
        </ViewModel:MainWindowViewModel.ContextMenuTemplate>
        <ViewModel:MainWindowViewModel.PaneHeaderTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <ContentPresenter Content="{Binding}" Width="150" ToolTip="{Binding}" />
                    <Button Command="{Binding DataContext.Close, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type tel:RadPane}}}"
                            CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type tel:RadPane}}}" 
                            HorizontalAlignment="Center" VerticalAlignment="Center" ToolTip="Close" BorderThickness="0" Width="16" Height="16">
                        <Image Source="Resources\Images\ImgClose.png"/>
                    </Button>
                </StackPanel>
            </DataTemplate>
        </ViewModel:MainWindowViewModel.PaneHeaderTemplate>
    </ViewModel:MainWindowViewModel>
</Window.DataContext>


I can't get this to working.
In the above PaneHeaderTemplate works fine but I am not able to pass the parameter for the ContextMenu Template. 

Is there any different way to do this?

1 Answer, 1 is accepted

Sort by
0
Rosen Vladimirov
Telerik team
answered on 11 Sep 2012, 06:38 AM
Hi,

Please check the code below for our suggestion how to implement the close command:
<Window.Resources>
    <DataTemplate x:Key="ContextMenu">
        <telerik:RadContextMenu InheritDataContext="False">
            <telerik:RadMenuItem Header="Floating"
                                        Command="telerik:RadDockingCommands.Floating" />
            <telerik:RadMenuItem Header="Dockable"
                                        Command="telerik:RadDockingCommands.Dockable" />
            <telerik:RadMenuItem Header="Save"
                                        Command="{Binding Save}"/>
            <telerik:RadMenuItem Header="Close" Command="telerik:RadDockingCommands.Close" CommandParameter="{Binding}" />
        </telerik:RadContextMenu>
    </DataTemplate>
 
    <DataTemplate x:Key="PanelHeaderTemplate">
        <StackPanel Orientation="Horizontal">
            <ContentPresenter Content="{Binding}" Width="150" ToolTip="{Binding}" />
            <Button Command="telerik:RadDockingCommands.Close"
                        CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:RadPane}}}"
                        HorizontalAlignment="Center" VerticalAlignment="Center" ToolTip="Close" BorderThickness="0" Width="16" Height="16">
                <Image Source="Resources\Images\ImgClose.png"/>
            </Button>
        </StackPanel>
    </DataTemplate>
</Window.Resources>
<Grid Background="Beige">
    <telerik:RadDocking>
        <telerik:RadDocking.DocumentHost>
            <telerik:RadSplitContainer>
                <telerik:RadPaneGroup>
                    <telerik:RadPane Header="Draggable"
                                        HeaderTemplate="{StaticResource PanelHeaderTemplate}"
                                        ContextMenuTemplate="{StaticResource ContextMenu}">
                        <TextBlock Text="SimpleText for the draggable item"/>
                    </telerik:RadPane>
                    <telerik:RadPane Header="NonDraggable"
                                        HeaderTemplate="{StaticResource PanelHeaderTemplate}"
                                        ContextMenuTemplate="{StaticResource ContextMenu}" CanFloat="False">
                        <TextBlock Text="SimpleText"/>
                    </telerik:RadPane>
                </telerik:RadPaneGroup>
            </telerik:RadSplitContainer>
        </telerik:RadDocking.DocumentHost>
    </telerik:RadDocking>
</Grid>
</Window>

As you can see we have applied some changes on the ContextMenu and on the Button. Now if you choose Close in the context menu, the RadPane will be closed.
Could you try this solution and inform us if it doesn't fit your needs?

Kind regards,
Rosen Vladimirov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
ContextMenu
Asked by
Karandeep Singh
Top achievements
Rank 1
Answers by
Rosen Vladimirov
Telerik team
Share this question
or