ContextMenu for GanttView in Silverlight?

5 posts, 1 answers
  1. Andrew
    Andrew avatar
    5 posts
    Member since:
    Jul 2012

    Posted 22 Aug 2012 Link to this post

    I have a WPF project which uses GanttView that I am trying to convert to SL, and I need to display a RadContextMenu in the GanttView.
    In WPF, the contextmenu is added in a style definition for targettype Telerik:EventContainer. (see code below).
    <Style TargetType="Telerik:EventContainer">
        <Setter Property="Height" Value="{Binding OriginalEvent.TaskHeight}" />
        <Setter Property="Margin" Value="0,2,0,2" />
        <Setter Property="Telerik:RadContextMenu.ContextMenu">
            <Setter.Value>
                <Telerik:RadContextMenu >
                    <Telerik:RadMenuItem Header="Copy Graph" Tag="Gantt" Click="ContextMenuCopy_Click">
                        <Telerik:RadMenuItem.Icon>
                            <Image Source="/Silverlight;component/Resources/Images/48x48/CopyImage.png" Width="16" Height="16" />
                        </Telerik:RadMenuItem.Icon>
                    </Telerik:RadMenuItem>
                    <Telerik:RadMenuItem IsSeparator="True"/>
                </Telerik:RadContextMenu>
            </Setter.Value>
        </Setter>
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Effect">
                        <Setter.Value>
                            <DropShadowEffect />
                        </Setter.Value>
                    </Setter>
                </Trigger>
            </Style.Triggers>
    </Style>

    Unfortunately, this doesn't work in Silverlight.  Is there any way to add a context menu to the GanttView?
    Also, since Style.Triggers don't work either, how can I add a DropShadowEffect to the Telerik:RelationContainer?

    I've been stuck on this for 2 days, so any help would be greatly appreciated. Thanks.

  2. Answer
    Miroslav Nedyalkov
    Admin
    Miroslav Nedyalkov avatar
    1718 posts

    Posted 23 Aug 2012 Link to this post

    Hello Andrew,

    For attaching the RadContextMenu in style using Silverlight you could refer to this article and this example.

    In Silverlight you may use VisualStates instead of Triggers, but they can only be used in the ControlTemplate of a control and not directly in the style. For more information how to use visual states you may refer to this article or check this one that gives a Silverlight replacement for the Triggers when using Blend.

    Hope this helps.

    All the best,
    Miroslav Nedyalkov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
  4. Andrew
    Andrew avatar
    5 posts
    Member since:
    Jul 2012

    Posted 23 Aug 2012 Link to this post

    Thanks Miroslav. The RadContextMenuXamlHolder from the example worked perfectly!
  5. Anne Lyon
    Anne Lyon avatar
    87 posts
    Member since:
    Jan 2010

    Posted 11 Jan 2013 Link to this post

    Hi, I would like to attach a context menu to a tree-column in the task-tree. Preferable only child tasks and not parent (summary) tasks.
    I have implemented the code in the suggested example and the context menu works fine if I for instance attach it to a EventContainer:
    in MainPage.xaml:
    <Setter Property="telerik:RadContextMenu.ContextMenu" Value="{Binding Path=ContextMenu, Source={StaticResource ContextMenuHolder}}" />

    But if I add the same line for a TreeCellContainer the context menu does not display:

    <Style TargetType="telerik:TreeCellContainer" BasedOn="{StaticResource TreeCellEContainerStyle}">
        <Setter Property="telerik:RadContextMenu.ContextMenu" Value="{Binding Path=ContextMenu, Source={StaticResource ContextMenuHolder}}" />
    </Style>

    My treeView columns are defined like this:
    <telerik:RadGanttView.Columns>
         <telerik:ColumnDefinition  Header="NB!" ColumnWidth="40" >
             <telerik:ColumnDefinition.CellTemplate>
                 <DataTemplate>
                     <StackPanel Orientation="Horizontal">
                          <Image x:Name="imgKlipp" Source="{Binding Progress, Converter={StaticResource DblToImageConverter}}" HorizontalAlignment="Right" Stretch="None" />
                     </StackPanel>
                 </DataTemplate>
             </telerik:ColumnDefinition.CellTemplate>
         </telerik:ColumnDefinition>
           
         <telerik:TreeColumnDefinition Header="AO'er" MemberBinding="{Binding Title}" ColumnWidth="160">
         </telerik:TreeColumnDefinition>
     </telerik:RadGanttView.Columns>

    It is only the TreeColumnDefinition I want a context menu for, NOT the ColumnDefinition.
    Am I using the right target container for the items in the treeview? How do I make sure only the child tasks/events have a context menu in the task tree and not the parent summarty tasks?

    Anne
  6. Ventzi
    Admin
    Ventzi avatar
    114 posts

    Posted 15 Jan 2013 Link to this post

    Hello Anne Lyon,

    Yes, you are using the right container, but if you like to add a RadContextMenu to the TreeCellContainer you need to override the ContentTemplate property. Also you would like to have RadContextMenu only on sub items. This could be easily achieve if you get the Level property of the clicked item. We've made a sample project where it is demonstrated how to implement the RadContextMenu only on sub items.

    Kind Regards,
    Ventzi
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
DevCraft banner