I just upgraded to version Q1 2010. In order to hide the existing menu items in a radpane and add a custom menu item I was using code similar to the following:
RadPane.MenuCommands.Clear();
RadPane.MenuCommands.Add(mycustommenucommand);
But with Q1 2010 the MenuCommands property of the RadPane object is null and the help says that it is deprecated. How do I hide the existing menu commands and add a custom menu command now?
Thanks,
Craig
8 Answers, 1 is accepted
Thanks!
You can customize the drop down menu by changing the ContextMenuTemplate property of the RadPane control. Please, find the attached project that demonstrates the approach (the demo uses commands, but you could implement it however you like to).
Regards,
Rosi
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
{System.Reflection.TargetInvocationException: 调用的目标发生了异常。 ---> System.InvalidCastException: 无法将类型为“System.Windows.Controls.ContentControl”的对象强制转换为类型“Telerik.Windows.Controls.RadPane”。
位于 FlashFoolWarn.Views.MeetingCenter.UrgentPlanManageMap.InitializeComponent()
位于 FlashFoolWarn.Views.MeetingCenter.UrgentPlanManageMap..ctor()
--- 内部异常堆栈跟踪的结尾 ---
位于 System.Windows.Navigation.PageResourceContentLoader.EndLoad(IAsyncResult asyncResult)
位于 System.Windows.Navigation.NavigationService.ContentLoader_BeginLoad_Callback(IAsyncResult result)}
Could you please give us some more information about the your scenario and the version of RadControls for Silverlight you use? If you could send us a sample project that reproduces the problem this would be of great help.
Kind regards,Miroslav Nedyalkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Is there a way to control the RadDocking from the C# code and not the xmal? I was following the localization example for the RadDocking and ran into the same problem as Criag identified below. But the DockingMenu example you included in that thread was all done within the xaml and we would like a solution from within C# code.
The ContextMenuTemplate has very few options to use with C#. The only one I can get to work in the
ContextMenuTemplate which as you know removes the RadDocking control entirely.
Another way of asking my question, can you implement the following code from your example using ContestMenuTemplate?
pane.MenuCommands.Clear();
// FloatingMenuCommand
pane.MenuCommands.Add( new MyCommand
{
HeaderExpression = p => "Floating[localized]",
IsCheckedExpression = p => p.IsFloating && !p.IsDockable,
IsEnabledExpression = p => p.IsPinned && p.CanFloat,
ItemClickAction = p => p.MakeFloatingOnly()
} );
// DockableMenuCommand
pane.MenuCommands.Add( new MyCommand
{
HeaderExpression = p => "Dockable[localized]",
IsCheckedExpression = p => p.IsDockable && p.IsPinned && !p.IsInDocumentHost,
IsEnabledExpression = p => p.IsPinned && ( !p.IsInDocumentHost || p.CanFloat ),
ItemClickAction = p => p.MakeDockable()
} );
// TabbedDocumentMenuCommand
pane.MenuCommands.Add( new MyCommand
{
HeaderExpression = p => "TabbedDocument[localized]",
IsCheckedExpression = p => p.IsInDocumentHost,
IsEnabledExpression = p => p.IsPinned && p.CanDockInDocumentHost,
ItemClickAction = p => p.MoveToDocumentHost()
} );
// AutoHideMenuCommand
pane.MenuCommands.Add( new MyCommand
{
HeaderExpression = p => "AutoHide[localized]",
IsCheckedExpression = p => !p.IsPinned,
IsEnabledExpression = p => !p.IsFloating && !p.IsInDocumentHost && p.CanUserPin,
ItemClickAction = p => p.IsPinned = !p.IsPinned
} );
// CloseMenuCommand
pane.MenuCommands.Add( new MyCommand
{
HeaderExpression = p => "Close[localized]",
IsCheckedExpression = p => p.IsHidden,
IsEnabledExpression = p => p.CanUserClose,
ItemClickAction = p => p.IsHidden = true
} );
foreach ( var mc in pane.MenuCommands )
{
mc.NotifyPaneStateChange( pane );
}
You could manipulate the context menu generated through the ContextMenuTemplate using the following code:
RadContextMenu menu;
private
void
RadContextMenu_Loaded(
object
sender, RoutedEventArgs e)
{
if
(menu ==
null
)
{
menu = sender
as
RadContextMenu;
menu.Items.Add(
"Menu item 1"
);
}
}
<
telerik:RadPane
x:Name
=
"pane"
Header
=
"pane"
>
<
telerik:RadPane.ContextMenuTemplate
>
<
DataTemplate
>
<
telerik:RadContextMenu
Loaded
=
"RadContextMenu_Loaded"
>
<
telerik:RadMenuItem
Header
=
"item"
/>
</
telerik:RadContextMenu
>
</
DataTemplate
>
</
telerik:RadPane.ContextMenuTemplate
>
...
</
telerik:RadPane
>
Hope this information helps! Sincerely yours,
Miroslav Nedyalkov
the Telerik team
Unfortunately the only way to change the ContextMenu of the RadPane is to use a DataTemplate, however it is not needed to use RadContextMenu Loaded event as it is shown in the previous post but you can just set a Command to the added menu item. More info and code samples on how to do this you can find in this help article.
Kind regards,
Boyan
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>