ContextMenu for RadPane

2 posts, 0 answers
  1. Karandeep Singh
    Karandeep Singh avatar
    4 posts
    Member since:
    May 2010

    Posted 07 Sep 2012 Link to this post

    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?

  2. Rosen Vladimirov
    Admin
    Rosen Vladimirov avatar
    640 posts

    Posted 11 Sep 2012 Link to this post

    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.

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top