We help IT Professionals succeed at work.
Get Started

Silverlight data binding to septate class c#

BrentDenny
BrentDenny asked
on
691 Views
Last Modified: 2012-05-11
I have a canvas that i need to add some mouse events like mouse-leave and mouse-enter  ect...

i have a separate class that is  will be handling the mouse events but i need to bind them from that page to the separate class NOT to code behind. Here is were i have bound to the class USAmap
i have used it and it works just fine for properties  but I dont now how to bind the mouse events for a canvas.
 
 <UserControl.Resources>
        <ViewModel:USAmap x:Key="ViewModel" MapItemName="USmap"/>
     </UserControl.Resources>
    <Grid x:Name="LayoutRoot" DataContext="{Binding Source = {StaticResource ViewModel}}">


<Canvas x:Name="Washington" Width="600" Height="398" Canvas.Left="0" Canvas.Top="0">
                    <Path x:Name="Path" Width="72.6667" Height="52.6219" Canvas.Left="38.831" Canvas.Top="19.7767" Stretch="Fill" Fill="#671BA51B" Data="F1 M 38.831,51.7767L ect...."/>
                </Canvas>

Also is there a way to still find out what the sender is and access it.
to change its properties once clicked. like in the code example

public class USAmap ......

 public static MouseButtonEventHandler _routedEvent;

public void c_MouseMove(object sender, MouseEventArgs e)
        {
            Canvas c = sender as Canvas;
            ResetLastSelected();

            if (!string.IsNullOrEmpty(c.Name))
            {
                if (c.Name != lastSelected)
                {
                 //   HideMenu();
                }

                lastSelected = c.Name;
                lastSelected2 = c.Name + "_HotSpot";
               // Canvas selectedCanvas2 = this.FindName(lastSelected2) as Canvas;

              //  SetCanvasColor(c, Color.FromArgb(255, 127, 255, 0), 2, Colors.Green, selectedCanvas2);
            }
        }

Open in new window

Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 20 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE