My RadContextMenu is not data bound its simply static xaml markup.
4 Answers, 1 is accepted
If you menu is not bound then all you have to do is to enumerate the Items property, cast the objects to RadMenuItem and then cast the Header property to string.
Let us know if you need more information.
Greetings,
Hristo
the Telerik team
public static class RadMenuExtensions
{
/// <summary>
/// Finds an item by its text.
/// </summary>
/// <param name="menu">The menu.</param>
/// <param name="text">The text.</param>
/// <returns></returns>
public static RadMenuItem FindByText(this MenuBase menu, string text)
{
RadMenuItem foundItem = null;
foreach (RadMenuItem item in menu.Items)
{
// watch out for seperators with null headers
if (item.Header != null)
{
if (item.Header.ToString().ToLowerInvariant().Equals(text.ToLowerInvariant()))
foundItem = item;
}
}
return foundItem;
}
}
This is the modified code so that it will work with bound menu too:
public
static
class
RadMenuExtensions
{
/// <summary>
/// Finds an item by its text.
/// </summary>
/// <param name="menu">The menu.</param>
/// <param name="text">The text.</param>
/// <returns></returns>
public
static
RadMenuItem FindByText(
this
MenuBase menu,
string
text)
{
RadMenuItem foundItem =
null
;
foreach
(
object
item
in
menu.Items)
{
RadMenuItem menuItem = menu.ItemContainerGenerator.ContainerFromItem(item)
as
RadMenuItem;
string
header = Convert.ToString(menuItem.Header);
if
(header.ToLowerInvariant().Equals(text.ToLowerInvariant()))
{
foundItem = menuItem;
break
;
}
}
return
foundItem;
}
}
I hope that this will help you.
All the best,
Hristo
the Telerik team