5 Answers, 1 is accepted
0
Hi runes,
Here is an example how to change RadMenuItem Icons in code:
This is the page.xaml
<UserControl x:Class="SilverlightApplication26.Page" |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
xmlns:nav="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation" |
Width="400" Height="300"> |
<StackPanel x:Name="LayoutRoot" Background="White"> |
<RadioButton Content="Click Me to Open the RadContextMenu"> |
<nav:RadContextMenu.ContextMenu> |
<nav:RadContextMenu EventName="Click" x:Name="radContextMenu1"> |
<nav:RadMenuItem Header="Item 1" /> |
<nav:RadMenuItem Header="Item 2" /> |
</nav:RadContextMenu> |
</nav:RadContextMenu.ContextMenu> |
</RadioButton> |
</StackPanel> |
</UserControl> |
and this is the code-behind:
using System; |
using System.Windows; |
using System.Windows.Controls; |
using System.Windows.Media.Imaging; |
using Telerik.Windows; |
using Telerik.Windows.Controls; |
namespace SilverlightApplication26 |
{ |
public partial class Page : UserControl |
{ |
public Page() |
{ |
InitializeComponent(); |
radContextMenu1.AddHandler(RadMenuItem.ClickEvent, new RoutedEventHandler(OnMenuItemClick)); |
} |
private void OnMenuItemClick(object sender, RoutedEventArgs e) |
{ |
RadRoutedEventArgs args = e as RadRoutedEventArgs; |
RadMenuItem item = args.OriginalSource as RadMenuItem; |
string header = Convert.ToString(item.Header); |
if (header == "Item 1") |
{ |
item.Icon = new Image() { Source = new BitmapImage(new Uri("rasterCard3D.png", UriKind.Relative)) }; |
} |
else |
{ |
item.Icon = new Image() { Source = new BitmapImage(new Uri("rasterCard3DMonoChrome.png", UriKind.Relative)) }; |
} |
} |
} |
} |
Let us know if you need more help.
Best wishes,
the Telerik team
Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
runes
Top achievements
Rank 1
answered on 25 Mar 2009, 07:37 AM
Thank,
but how do i do it in loded the contax menu??????????
i want that the icons added in loded the contax menu.
but how do i do it in loded the contax menu??????????
i want that the icons added in loded the contax menu.
0
Hello runes,
I'm not sure that I understand your question. What do you mean with in Loaded event?
You can add the icons in XAML or you can add them in the Page constructor. Just give Name to the contextMenu so that you have access in the code behind and after the InitializeComponent method iterate the Items of the contextMenu and set their Icon property (like in my previous post).
Let me know if you need more help.
Regards,
the Telerik team
Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Mohit Vijay
Top achievements
Rank 1
answered on 27 Aug 2009, 09:56 PM
Hello Telerik People,
Can you please convert below code for vb.net?
Can you please convert below code for vb.net?
private void OnMenuItemClick(object sender, RoutedEventArgs e) |
{ |
RadRoutedEventArgs args = e as RadRoutedEventArgs; |
RadMenuItem item = args.OriginalSource as RadMenuItem; |
string header = Convert.ToString(item.Header); |
if (header == "Item 1") |
{ |
item.Icon = new Image() { Source = new BitmapImage(new Uri("rasterCard3D.png", UriKind.Relative)) }; |
} |
else |
{ |
item.Icon = new Image() { Source = new BitmapImage(new Uri("rasterCard3DMonoChrome.png", UriKind.Relative)) }; |
} |
} |
0
Hi Mohit Vijay,
I used converter.telerik.com and below is the result I got:
Hope this helps.
All the best,
Nick
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
I used converter.telerik.com and below is the result I got:
Private Sub OnMenuItemClick(sender As Object, e As RoutedEventArgs) |
Dim args As RadRoutedEventArgs = TryCast(e, RadRoutedEventArgs) |
Dim item As RadMenuItem = TryCast(args.OriginalSource, RadMenuItem) |
Dim header As String = Convert.ToString(item.Header) |
If header = "Item 1" Then |
item.Icon = New Image() |
Else |
item.Icon = New Image() |
End If |
End Sub |
Hope this helps.
All the best,
Nick
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.