Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
755
Setting the icon programatically
posted

Hi,

How may I set the icon of a XamWebMenuItem programatically? I'm trying to do it but each time I got an erro when I try to open the menu :S

 

Cheers.

Parents
  • 7922
    Verified Answer
    posted

    Hi

    You can set icon programatically as shown follow:

    public MainPage()
    {
     InitializeComponent();
     Loaded += new RoutedEventHandler(MainPage_Loaded);
    }

    void MainPage_Loaded(object sender, RoutedEventArgs e)
    {
     // Create the image element.
     Image simpleImage = new Image();
     
     // Create source.
     BitmapImage bi = new BitmapImage();
     bi.UriSource = new Uri("icon_Welcome.png", UriKind.RelativeOrAbsolute);

     // Set the image source.
     simpleImage.Source = bi;

     ((XamWebMenuItem)this.MyMenu.Items[0]).Icon = simpleImage;
    }

     

    You should add your icon as a resource to your project.

    Todor

Reply Children