Edit this page

Icons

The RadMenu allows you to display an icon for each of the menu items. It can be done by setting the Icon property of the RadMenuItem. This property is of type Image, so you have to provide an element of type Image for it.

As there are two ways to populate the RadMenu with data, this topic will explain you how to set this property in both of them.

Setting the Icon of a Static Item

To learn more about this way of populating the RadMenu with static data take a look at the Using Static Items topic.

By using static items you can directly access the Icon property of each item. Respectively you can set it directly:

<telerik:RadMenuItem Header="New File">
    <telerik:RadMenuItem.Icon>
        <Image Source="/Images/newFile.png" 
               Stretch="None" />
    </telerik:RadMenuItem.Icon>
</telerik:RadMenuItem>

Here is a snapshot of the result.

Setting the Icon of a Dynamic Item

To learn more about this way of populating the RadMenu with dynamic data take a look at the Binding to Dynamic Data topic.

When using dynamic items, you have to bind the Icon property to a property of the data item. To see how to do this read here.

The specific here is that your data item should expose a property of type Image, so the Icon property can be bound properly. In most of the cases you will use this property with the RadMenuItem, so you can make it read-only property, that wraps another property of your data item. For example, here is an ImageUrl property of type Uri, that is wrapped inside an Icon property of type Image.

public class MenuItem
{
    //...

    public Uri IconUrl
    {
        get;
        set;
    }

    public Image Icon
    {
        get
        {
            return new Image()
            {
                Source = new BitmapImage(this.IconUrl)
            };
        }
    }

    //...
}
Public Class MenuItem
    '...
    Public Property IconUrl() As Uri
        Get
        End Get
        Set(value As Uri)
        End Set
    End Property
    Public ReadOnly Property Icon() As Image
        Get
            Dim img As New Image()
            img.Source = New BitmapImage(Me.IconUrl)
            Return img
        End Get
    End Property
    '...
End Class

The result is the same.

See Also