none
Image.Source is Not working in Mouse over...

    Question

  • Hi to all,

     I have tried so many thing to change the image of my menus when mouse gets over on all menu items but its not working and its giving runtime error...

    Monday, February 23, 2009 6:12 AM

Answers

  •  Hi,

    You Haqve to use Object name  and then add evendhandler to that.

    for e.g if you have create a image like this Image img=new Image();

    then you can attach handler like this 

    img.MouseEnter+=

    It is same like VB C# programming in web or windows application.

    Tuesday, February 24, 2009 10:02 AM

All replies

  •  Hi,

    Which Error it is giving.

    Can you paste your code of setting Image Source.

    Monday, February 23, 2009 7:21 AM
  • Hi,

    Thanks for your reply well now given code is working for me now, but now my problem is how to do the same thing by using javascript means i want to pass the id of my images and i want to perform the mouse over and mouse out effects so what to do to accomplish that... thanks and awaiting for your valuable reply.....  

    Private
    Sub image1_MouseEnter(ByVal sender As Object, ByVal e As System.Windows.Input.MouseEventArgs) Handles image1.MouseEnter

    Dim bmi As New BitmapImage

    bmi = New BitmapImage(New Uri("mps/company/roll_home.jpg", UriKind.Relative))

    image1.Source = bmi

    End Sub

    Monday, February 23, 2009 8:06 AM
  •  Hi,

    I am confused here.

    If you can directly do Mouse over and mouse out from Silverlight then why do you want to call a javascript function and do that.

    Any way you can expose a Scriptable method which will do mouse over and mouse out.

    You can Call a Javascript method  from silverlight and can call Silverlight Methods from javascript.

    check this link.

    http://michaelsync.net/2008/01/18/silverlight-tipstricks-communicating-between-javascript-and-c

    Monday, February 23, 2009 8:49 AM
  • Hi Thanks for your Response,

               Well i want that functionality from javascript because i m developing an application that contains 7 pages and  all pages contains different header menus.. and each menu contains 8-10 menu items... so if i do the same thing from .xaml then i have to write the code for each and every menu items but i want to pass the id in one unique function and i wanna to perform mouse over and mouse out event based on Id so that i will not have to write the bunch of functions... so how to do such things ?

    Monday, February 23, 2009 8:59 AM
  •  Hi,

    I have already sent you a link which contains sample related to acessing Silverlight Content from javascript

    but let me clear few things to you.You Can not acess Silverlight Controls directly from javascript.

    You Can get and set there values using fuctions and methods but for that also you need to do that thing in all those 7-8 pages.

    So i do not think your approach will be having any advantage.

    Monday, February 23, 2009 9:24 AM
  • Hi,

        I think Your Suggestion is very true, so  what i am thinking now that i have to pass id from all my image controlls through mouseEnter eventArgument and then i will set the Images for mouser over and mouse out... now is this Proper way or not ?  

    Monday, February 23, 2009 9:31 AM
  •  Hi,

    Yes it is a Proper way.

    But why do you think you need to pass Id.

    You can add two handler for mouse enter and leave.By casting sender object in those events you can get Image type you can check their name and image source.  So you need to write two handler only on per page basis.

    Monday, February 23, 2009 10:09 AM
  • Hi,

    I am extremely sorry for late reply...

    Well i think Your suggestion is really very good and proper...

    But can u please tell me how to write general Mouse Enter and Mouse Out Event Handlers... because i have not write such code in silverlight...

    So please suggest me...

    Tuesday, February 24, 2009 4:51 AM
  • Hi,

     in code behind of xaml i will have to write mouse Enter and mouse Leave for all images but i want to make it as general... means i want to use only one mouse enter and one mouse leave Event handler... so what can i do for that ????

    Tuesday, February 24, 2009 8:08 AM
  •  Hi,

    You Can add Handler in Xaml or codebehid.

    In loaded event add handlers for image like this.

    //contentElement ia an Image

        contentElement.MouseEnter += new MouseEventHandler(contentElement_MouseEnter);
              
         ContentElement.MouseLeave += new MouseEventHandler(contentElement_MouseLeave);

    //Events will be like this.

       void contentElement_MouseEnter(object sender, MouseEventArgs e)
            {
              Image img=sender as Image;
    //Here you can check source or other stuff

           }

    //from xaml also you can do like that.

    <Image MouseEnter="contentElement_MouseEnter" Source="-------"/>

    Tuesday, February 24, 2009 8:42 AM
  • Hi,

    Thanks for such valuable answer, well let me implement this... then i will reply to u...

    Thanks...

    Tuesday, February 24, 2009 8:57 AM
  • Hi,

    As you told that i have to register each images for mouse enter and mouse leave Sub right ?

    but its not supporting image.mouseenter or image.mouseleave in code behind ?

    well i am using vb not c# as a language , so is this an issue for that ?

    Tuesday, February 24, 2009 9:13 AM
  •  Hi,

    You Haqve to use Object name  and then add evendhandler to that.

    for e.g if you have create a image like this Image img=new Image();

    then you can attach handler like this 

    img.MouseEnter+=

    It is same like VB C# programming in web or windows application.

    Tuesday, February 24, 2009 10:02 AM
  • Hi,

    Its still not works, according to ur last reply i have taken image as object but then also i am not getting mouseEnter eventhandler or else..

    And these things i have to do in new() constructor right ???

    Tuesday, February 24, 2009 1:04 PM
  • Hi,

    i get it whatever i was needed.. thanks for ur kind response and yes i have done through your suggestion only...

    Wednesday, February 25, 2009 4:59 AM