Recommended

Skip Navigation LinksHome / Tips / View Tip

Tip: How to disable controls in Silverlight?

+ Add to SilverlightShow Favorites
4 comments   /   posted by Denislav Savkov on Sep 17, 2008
(0 votes)
Categories: Controls and UI

Currently only Silverlight controls that derive from System.Windows.Controls.ContentControl support disabling. Those that support have IsEnabled property. However in the release version of Silverlight 2.0 IsEnabled will be a property of the System.Windows.Control class. Also, if the property is changed on a parent control the new value will be applied to all the children of the control.

C#

myButton.IsEnabled = false;

XAML

<Button IsEnabled="False"/>

If you need to disable your controls before the release you must write your own implementation. It is useful to set the UIElement.IsHitTestVisible property to false. It prevents the UIElement from raising input events and receiving focus, and is applied to the children elements.

XAML

<StackPanel IsHitTestVisible="False">
    <...><!--IsHitTestVisible property of items is forced to False-->
</StackPanel>

That's it!

Share


Comments

Comments RSS RSS
  • RE: Tip: How to disable controls in Silverlight?  

    posted by Dave on Sep 17, 2008 11:20

    Where do you see the IsEnabled property? My controls in SL2 derive from UserControl (which derives from... up the chain) but IsEnabled isn't available. MSDN also says it's not available: http://msdn.microsoft.com/en-us/library/system.windows.controls.usercontrol_members(VS.95).aspx

    Have you actually used it? I see other blog posts where they have examples that are working, but I'm at a loss of how.

  • RE: Tip: How to disable controls in Silverlight?  

    posted by Dave on Sep 17, 2008 11:21

    And of course I see the error right after I push "Add Comment". I thought that UserControl derived from ContentControl but apparently it doesn't. Fun times.

  • RE: Tip: How to disable controls in Silverlight?  

    posted by iiordanov on Sep 18, 2008 00:16

    Hi Dave,

    Yes, this is the funny thing here, the Button control does not have this IsEnabled property because it does NOT derive from ContentControl. We hope this will change in future releases of Silverlight.

  • RE: Tip: How to disable controls in Silverlight?  

    posted by Wilson Chan on Sep 17, 2009 03:36
    Try property Visibility

     

    Visibility = System.Windows.Visibility.Collapsed;

Add Comment

 
 

   
  
  
   
Please add 4 and 4 and type the answer here:

Help us make SilverlightShow even better and win a free t-shirt. Whether you'd like to suggest a change in the structure, content organization, section layout or any other aspect of SilverlightShow appearance - we'd love to hear from you! Need a material (article, tutorial, or other) on a specific topic? Let us know and SilverlightShow content authors will work to have that prepared for you. (hide this)