locked
Mouse over to label behaviors! RRS feed

  • Question

  • Hi all, im trying to make a behavior.

    When i move my mouse over a button i want the label to show the button tag.. how do i do that? i went online for hours trying to find samples somewhat simular to it.
    Tuesday, January 19, 2010 2:08 AM

All replies

  • Hi Owen,
                     I am not sure if you need a behavior to do that (if I understand your question correctly).

    Try following steps and let me know if this works for you.

    [WPF / Silverlight]
        1. Edit Template of button (You can edit in same document or External Resource dictionary or App.xaml)
        2. Select ContentPresenter in Objects and Timeline panel
        3. Set the Visibility to Collpased in properties pane
        4. Click on MouseOver state in State pane
        5. Move Timeline to 0.5 and set Visibility property to Visible
        6. Press F5

    On F5, "Button" tag will be visible when you mouseover the button. Is this what you intend to do?

    Thanks,
    Navit Saxena
    Tuesday, January 19, 2010 3:07 AM
  • no no. I have a label/textblock and a button on my silverlight page. When i mouse hover over my button i want the label/textblock to show the button tag. I want to do this in a behavior because i wont need to do alot of c# code per buttons.

    For example, i make a button on a page. i make a label on my page. i edit the button tag to "you hovered me". I want my behavior to work when i mouse over the button to make the label to display the button tag text.

    I looked at msdn and i dont know where to go to even get this done. On google, i cannot find a good source sample to get me anywhere(to deal with behaviors) which is very annoying.
    • Edited by Owen Barker Tuesday, January 19, 2010 4:09 AM editing
    Tuesday, January 19, 2010 4:07 AM
  • I found a solution after playing around with triggeraction. Took me a day to finally figure it out!

    here is how it works.

    1. make a button, make a label.
    2. edit the button tag to "you clicked me"
    3. Make an TargetedTriggerAction OR make an trigger and edit the class type and use this code:

    public class OnMouse : TargetedTriggerAction<Label>
    {
    	private Label targetLabel { get; set; }
    
    	public OnMouse()
    	{
    		targetLabel = this.Target;
    
    		if (null == targetLabel)
    			return;
    	}
    
    	protected override void Invoke(object o)
    	{
    		targetLabel.Content = this.AssociatedObjectTypeConstraint.GetField("tag").ToString();
    	}
    }

    • Proposed as answer by DaveyBoy1138 Tuesday, January 19, 2010 6:38 PM
    Tuesday, January 19, 2010 3:42 PM