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

Set icon property on run time

1 Answer 82 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Mohit Vijay
Top achievements
Rank 1
Mohit Vijay asked on 27 Aug 2009, 09:56 PM
Hello,

I want to set the icon property of RadMenuItem on run time, Actually, I want to change the imange, when mouse enter and also when mouse leave from that RadMenu item, so I need to set the image dynamically. Remember I am using vb.net.

Can you please provide me the code example for it?

1 Answer, 1 is accepted

Sort by
0
Kaloyan
Telerik team
answered on 01 Sep 2009, 08:23 AM
Hi Mohit Vijay,

Check the code snippet bellow:

 <UserControl.Resources> 
        <BitmapImage x:Key="defaultImage" UriSource="Dock.jpg" /> 
        <BitmapImage x:Key="hoverImage" UriSource="Tree.jpg" /> 
    </UserControl.Resources> 
 
    <Grid x:Name="LayoutRoot"
 
        <telerikNavigation:RadMenu Width="500" Height="30"
            <telerikNavigation:RadMenuItem Header="File"
                <telerikNavigation:RadMenuItem Header="Open" x:Name="radMenuItem" 
                        Click="RadMenuItem_Click" MouseLeave="RadMenuItem_MouseLeave" 
                        MouseEnter="RadMenuItem_MouseEnter"
                    <telerikNavigation:RadMenuItem.Icon> 
                        <Image Source="{StaticResource defaultImage}" Width="20" Height="20" /> 
                    </telerikNavigation:RadMenuItem.Icon> 
                </telerikNavigation:RadMenuItem> 
            </telerikNavigation:RadMenuItem> 
        </telerikNavigation:RadMenu> 
    </Grid> 
 Private Sub RadMenuItem_MouseEnter(ByVal sender As Object, ByVal e As MouseEventArgs) 
        Dim image As BitmapImage = Me.Resources("hoverImage"
        Dim imageSource As Image = radMenuItem.Icon 
 
        imageSource.Source = image 
    End Sub 
 
    Private Sub RadMenuItem_MouseLeave(ByVal sender As Object, ByVal e As MouseEventArgs) 
        Dim image As BitmapImage = Me.Resources("defaultImage"
        Dim imageSource As Image = radMenuItem.Icon 
 
        imageSource.Source = image 
    End Sub 
 
    Private Sub RadMenuItem_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) 
        RadMenuItem_MouseLeave(sender, Nothing) 
    End Sub 
 


Regards,
Kaloyan
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.
Tags
Menu
Asked by
Mohit Vijay
Top achievements
Rank 1
Answers by
Kaloyan
Telerik team
Share this question
or