Set icon property on run time

2 posts, 0 answers
  1. Mohit Vijay
    Mohit Vijay avatar
    11 posts
    Member since:
    Aug 2009

    Posted 27 Aug 2009 Link to this post

    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?

  2. Kaloyan
    Admin
    Kaloyan avatar
    920 posts

    Posted 01 Sep 2009 Link to this post

    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.
  3. DevCraft banner
Back to Top