(X) Hide this
    • Login
    • Join
      • Generate New Image
        By clicking 'Register' you accept the terms of use .
        Login with Facebook

Tip: How to disable controls in Silverlight?

(0 votes)
Denislav Savkov
>
Denislav Savkov
Joined Feb 11, 2008
Articles:   14
Comments:   6
More Articles
5 comments   /   posted on Sep 17, 2008
Tags:   denislav-savkov
Categories:   Controls

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!


Subscribe

Comments

  • -_-

    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.

  • iiordanov

    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;
  • -_-

    RE: Tip: How to disable controls in Silverlight?


    posted by sumit on Jan 15, 2011 09:35

    By using  IsHitTestVisible we cant disable the controls properly.

    i used IsHitTestVisible for disable my textbox for editing but by using tab its going in side the textbox for editing.

    can u tell me another property for disable my textbox for editing.

Add Comment

Login to comment:
  *      *       
Login with Facebook