Hidding ControllerContainer when mouse stop

Feb 19, 2010 at 4:03 PM

Hello !

 

I tried to hide the ControllerContainer  when the mouse is stoping (after X sec).

 

To do that, i created 2 visual states in my extended player :

1. ControllerContainer is hidden => Y Position = 28px

2. ControllerContainer is showed => Y Position = 0px

 

I attach in the MouseMove event on the ControllerContainer and when the event is fired :

- Clear a timeout (see below)

- Go to state 2

- Launch the timeout. When it's ended, go to state 1

 

But it doesn't work. I have an execption when i try to go to state 2.

 

Do you know an other way to do that ?

 

 

Best regards,

Guillaume

Coordinator
Feb 22, 2010 at 9:08 PM

How are you hiding the ControllerContainer?  Are you setting Visibility = Collapsed?  What exception do you get?

Feb 22, 2010 at 9:22 PM
Edited Feb 22, 2010 at 9:22 PM

No, i set the Y position (translate) to have a translate effect.he

 

I don't have my work here, but my exception is about the targettype not found.

Mar 4, 2010 at 9:22 AM

Hello,

 

i have solved my problem :

When the MouseMove event on my extended player is fired, i retrieve the position of my mouse, if the position is in the ControllerContainer, i show it else i hide it.

The timeout idea was bad.

 

Regardsn

Guillaume

Mar 11, 2010 at 9:44 AM

I'v created a patch for thoose who want the ControllerContainer to autohide when the mouse is not in active area, it also uses a default load fadeaway to show the user that there is a controlbar at the start.

Also the ControllerContainer doesnt require space by the MediaElement instead its placed at the bottom as overlay.

krohling is this something you can consider taking in to the source-code? I think is what the default behaivor should be like.

 

 

Index: Microsoft.SilverlightMediaFramework.Player/Player.cs
===================================================================
--- Microsoft.SilverlightMediaFramework.Player/Player.cs	(revision 7100)
+++ Microsoft.SilverlightMediaFramework.Player/Player.cs	(working copy)
@@ -23,6 +23,7 @@
     //will not be publicly available for the upcoming PDC release of the SMF.
     //Kevin Rohling 11-10-2009 12:12PM
     //[TemplatePart(Name = ElementName.PlaySpeedElement, Type = typeof(RotaryControl))]
+    [TemplatePart(Name = ElementName.ControllerContainer, Type = typeof(Grid))]
     [TemplatePart(Name = ElementName.PlayElement, Type = typeof(PlayControl))]
     [TemplatePart(Name = ElementName.FullScreenElement, Type = typeof(ToggleButton))]
     [TemplatePart(Name = ElementName.CurrentTimeElement, Type = typeof(TextBlock))]
@@ -94,6 +95,7 @@
         // template controls
         protected CoreSmoothStreamingMediaElement mediaElement;
         protected ContentPresenter mediaPresenterElement;
+        protected Grid controllerContainer;
         //Commented out playSpeedElement because the RotaryControl
         //will not be publicly available for the upcoming PDC release of the SMF.
         //Kevin Rohling 11-10-2009 12:12PM
@@ -122,6 +124,7 @@
         // template part names
         private static class ElementName
         {
+            public const string ControllerContainer = "ControllerContainer";
             public const string MediaPresenterElement = "MediaPresenterElement";
             public const string PlaySpeedElement = "PlaySpeedElement";
             public const string PlayElement = "PlayElement";
@@ -508,13 +511,11 @@
         protected override void OnMouseEnter(System.Windows.Input.MouseEventArgs e)
         {
             base.OnMouseEnter(e);
-            VisualStateManager.GoToState(this, "MouseOver", true);
         }
 
         protected override void OnMouseLeave(System.Windows.Input.MouseEventArgs e)
         {
             base.OnMouseLeave(e);
-            VisualStateManager.GoToState(this, "Normal", true);
         }
 
         protected override void OnContentChanged(object oldContent, object newContent)
@@ -572,6 +573,7 @@
         private void GetTemplateChildren()
         {
             mediaPresenterElement = GetTemplateChild(ElementName.MediaPresenterElement) as ContentPresenter;
+            controllerContainer = GetTemplateChild(ElementName.ControllerContainer) as Grid;
             //Commented out playSpeedElement because the RotaryControl
             //will not be publicly available for the upcoming PDC release of the SMF.
             //Kevin Rohling 11-10-2009 12:12PM
@@ -597,6 +599,12 @@
         // add child event handlers
         private void InitializeTemplateChildren()
         {
+            if (controllerContainer != null)
+            {
+                controllerContainer.MouseEnter += new System.Windows.Input.MouseEventHandler(controllerContainer_MouseEnter);
+                controllerContainer.MouseLeave += new System.Windows.Input.MouseEventHandler(controllerContainer_MouseLeave);
+            }
+
             // play / pause button
             if (playElement != null)
             {
@@ -700,6 +708,16 @@
             }
         }
 
+        private void controllerContainer_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
+        {
+            VisualStateManager.GoToState(this, "Normal", true);
+        }
+
+        private void controllerContainer_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
+        {
+            VisualStateManager.GoToState(this, "MouseOver", true);
+        }
+
         // remove child event handlers
         private void UninitializeTemplateChildren()
         {
Index: Microsoft.SilverlightMediaFramework.Player/themes/generic.xaml
===================================================================
--- Microsoft.SilverlightMediaFramework.Player/themes/generic.xaml	(revision 7100)
+++ Microsoft.SilverlightMediaFramework.Player/themes/generic.xaml	(working copy)
@@ -1518,21 +1518,17 @@
                     
                         
                             
-                            
                         
                         
                             
-                                
-                                    
-                                
                                 
                                     
-                                        
+                                        
                                     
                                 
                                 
                                     
-                                        
+                                        
                                     
                                 
                             
@@ -1592,7 +1588,16 @@
                         
                         
                         
-                        
+                        
+                            
+                                
+                                    
+                                        
+                                            
+                                        
+                                    
+                                
+