WPF XAML Changing Image opacity on IsEnabled state

I would like to have the image to have an opacity of .50 when the IsEnabled is false. I have been looking at multiple examples but still I am not able to grasp how to make it work.

Here is the full XAML of my custom control. Any help would be deeply appreciated.

<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="test.StopButtonControl" x:Name="UserControl" d:DesignWidth="85" d:DesignHeight="85"> <Grid x:Name="LayoutRoot"> <Image x:Name="StopButtonUI" Source="Images/stop.png" Stretch="Fill" MouseUp="StopButtonClick"/> </Grid> </UserControl>

--------------Solutions-------------

You can couple the Image's Opacity property to its IsEnabled property via a style trigger as follows:

<Grid x:Name="LayoutRoot">
<Image x:Name="StopButtonUI" Source="Images/stop.png" >
<Image.Style>
<Style TargetType="Image">
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Opacity" Value="0.5" />
</Trigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
</Grid>

This will set the Opacity to 0.5 when IsEnabled is false.

The Image's IsEnabled property will be triggered when the UserControl has its IsEnabled property changed as a result of property inheritance i.e. the image is a child of the user control so it will have its IsEnabled property set too.

Category:wpf Time:2010-12-30 Views:0

Related post

  • How to make a loading graphic in WPF XAML? 2009-01-23

    So I have a little WPF XAML that gets the titles of my RSS feed and puts them in a ListBox. However, it takes about 2 seconds to load. How can I have put some kind of AJAXy spinning graphic in the ListBox until the data is there? Here is the code:

  • Convert WPF (XAML) Control to XPS Document 2009-02-02

    Can I take an Existing WPF (XAML) Control, databind it and turn it into an XPS document that can be displayed and printed using the WPF XPS Document Viewer? If so, how? If not, how should I be doing ‘reporting’ in WPF using XPS/PDF/etc? Basically I w

  • In WPF/XAML how do I change the size of a paragraph of text using a scroll bar? 2009-03-19

    I'm new to WPF/XAML & I'm just doing a training exercise at the moment. I've got a noddy application and I want to change the size of the text in a tag based on the position of a scroll bar. The text is defined by this code: <FlowDocumentScrol

  • Does WPF/Xaml have something like Flex/MXML's ViewStack 2009-03-22

    ViewStack in Flex/MXML is a container/panel control that holds multiple children but only makes one visible at a time, useful for implementing your own tab-style controls. Does WPF/Xaml have a class that works the same as this? I know it has its own

  • What's the Best Way to Catch the Return Key in a PasswordBox? (WPF/XAML) 2009-07-24

    What's the best way to catch the return key in a PasswordBox? (WPF/XAML) I have a TextBox field and a PasswordBox field on my login form (for username and password entry). I also have a login button which invokes the method that performs the login va

  • Convert WPF XAML to Silverlight XAML 2009-12-10

    I have question about using XAML across the WPF and Silverlight platforms. Background: I have a silverlight app that needs to pass the Xaml to WPF and do some calculation to update the XAML. When I run the changes in WPF, I parse the XAML and convert

  • WPF/XAML code generators 2010-03-22

    Do you use a code generator for WPF/XAML? If so, in what capacity? Is it 3rd party/in-house? --------------Solutions------------- i know that XAML power toys got some code generation but i don't know what it does. I've used the xaml export in InkScap

  • How to save user imputed value in TextBox? (WPF, XAML) 2010-04-24

    How to save user imputed value in TextBox? (WPF XAML) So in my xaml window I have a TextBox. User sturts my application inputs some values in to it and presses a button or hints Enter. He closes an app. Opens it up again. How to make his inputs be sa

  • EventTrigger RoutedEvent in wpf xaml 2010-05-06

    I have a problem in wpf xaml and i'm pretty new on this so it may be something basic i want to rotate a ellipse 360 degree <Ellipse Name="test" Fill="Black" StrokeThickness="5" Margin="0,0,0,0" Height="66"> <Ellipse.Triggers> <EventTri

  • Binding a control to a data class using WPF/XAML 2010-08-19

    I am trying to bind a data class to a ListView control in WPF, but can't seem to get it working. I can bind it at run-time and get it working using the following: this.DataContext = DataSet; But, if I try the following in the WPF/XAML is doesn't work

  • Is there a standalone visual editor for WPF xaml files? 2010-10-20

    Is there a stand-alone visual (WYSIWYG) editor for WPF xaml files like the Visual Studio 2010 designer? The VS2010 one crashes all the time and is very slow (there are lots of threads on XAML slowness in VS, but all the recommendations seem to point

  • WPF/XAML vs MVC Paradigm: flawed in the very fundamental design 2011-01-29

    In MVC a model can have multiple views, in WPF a XAML code-behind model is tight to 1 single XAML (view) isn't WPF/XAML flawed from the start in respect to MVC ? --------------Solutions------------- I recommend looking at MVVM for use with WPF. You'r

  • Nested curly brackets {{ }} in WPF/XAML 2011-10-01

    What is the meaning of nested curly brackets in attribute values in WPF/XAML markup? As in the following example: <ListBox ItemsSource="{Binding Source={StaticResource pictures}}"> --------------Solutions------------- That binds the ItemsSource

  • How to change scrolling behaviour when resizing window in WPF/XAML 2011-11-30

    Research Currently when working with WPF/XAML, the default scrolling behaviour for the scroll bar is that the VerticalScrollBarVisibility = Visible and the HorizontalScrollBarVisibility = Auto. This means the vertical scroll bar is always visible whi

  • WPF / Xaml: tag not available. I just don't get it. Who can explain the compiler message? 2011-12-25

    I am new to WPF / Xaml. I tried to run a demo program to test WPF with NHibernate. I used the VmWrapperDemo but i cant get it compiled! <Window x:Class="VmWrapperDemo.View.WindowMain" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentatio

  • Different Color to each side in Border in WPF XAML? 2012-03-28

    I want to have different color to each side of a border in WPF XAML. How can i do this. <Border BorderThickness="1,2,3,4" BorderBrush="Blue"></Border> --------------Solutions------------- Maybe? <DockPanel LastChildFill="True"> <

  • WPF XAML Change multiple ellipses colors with data binding 2014-01-07

    I'm currently creating a connect-4 game in order to learn WPF & XAML. I made the UI but I'm stuck on a problem. Below you can see an extract of the XAML code concerning the board of the game : <Grid DockPanel.Dock="Bottom" Background="#FF1506A

  • How to bind ControlTemplate Enabled property to Opacity in WPF XAML 2009-04-27

    In WPF inside XAML how to extend a ControlTemplate as such that when applied to a button and the button gets disabled it fades to 0.5 opacity while disabled and once enabled fades back to 1.0 opacity. This visual effect should work also when a parent

  • WPF DatePickerTextBox- change font color / opacity when IsEnabled == false 2011-02-16

    I'm having a hard time trying to style myself out of the problem specified in the title. Has anyone here done that? When the DatePicker control is disabled the font on the DatePickerTextBox is gray and hard to read. I'm changing to change that. Regar

Copyright (C) pcaskme.com, All Rights Reserved.

processed in 0.326 (s). 13 q(s)