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

ContextMenu for GanttView in Silverlight?

4 Answers 120 Views
GanttView
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 22 Aug 2012, 04:25 PM
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.

4 Answers, 1 is accepted

Sort by
0
Accepted
Miroslav Nedyalkov
Telerik team
answered on 23 Aug 2012, 07:10 AM
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.

0
Andrew
Top achievements
Rank 1
answered on 23 Aug 2012, 03:23 PM
Thanks Miroslav. The RadContextMenuXamlHolder from the example worked perfectly!
0
Anne Lyon
Top achievements
Rank 1
answered on 11 Jan 2013, 01:20 PM
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
0
Ventzi
Telerik team
answered on 15 Jan 2013, 11:13 AM
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.

Tags
GanttView
Asked by
Andrew
Top achievements
Rank 1
Answers by
Miroslav Nedyalkov
Telerik team
Andrew
Top achievements
Rank 1
Anne Lyon
Top achievements
Rank 1
Ventzi
Telerik team
Share this question
or