开发者

Silverlight: What is the easiest way to display disabled icons in silverlight

开发者_StackOverflow

In JS I would just change the resource url for the image. Is there a way in SL4 to apply some effect to image to make it grayish or something to indicate that command is disabled? Images are in png format.


Every Control within in Silvelright has an IsEnabled property. This can be used to define an enabled/disabled state which can then be styled as such in XAML (layer over the button to signal it is disabled for instance). Image however does not derive from Control and therefore does not have the IsEnabled property.

You could either create a custom Image class which will take care of applying the said behavior making use of the VisualStateManager.

You could also create a custom UserControl which can encapsulate the behavior you are looking for; making use of the two images and switching between them based on an exposed property; ie...IsEnabled.

You could also go the Image.Source route as you have done in JS which will change out the image being displayed; pushing the logic elsewhere and then changing out the source in code behind.


Alternatively, you could wrap the image within a hyperlink control (assuming you need to handle a click event), and set the hyperlink's IsEnabled property:

<HyperlinkButton x:Name="btnSave" Click="btnSave_Click" IsEnabled="False">
    <Image Source="/YourNamespace;component/Images/Icons/Save.png" Stretch="Fill"/>
</HyperlinkButton>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜