Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Change Button Image When Enabled/Disabled
Message
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Miscellaneous
Thread ID:
01470823
Message ID:
01470844
Views:
32
>>>>>>I put a button on a window and it's disabled. For the image I used a greyed out version of the image. When the button becomes enabled I'd like to swap the image to the enabled pic.
>>>>>>
>>>>>>Can someone point me in the right direction?
>>>>>>
>>>>>>Thanks
<Button x:Name="MyButton">
>>>>>            <StackPanel>
>>>>>                <TextBlock>Do Something</TextBlock>
>>>>>                <Image >
>>>>>                    <Image.Style>
>>>>>                        <Style>
>>>>>                            <Style.Triggers>
>>>>>                                <DataTrigger Binding="{Binding ElementName=MyButton,Path=IsEnabled}" Value="false">
>>>>>                                    <Setter Property="Image.Source" Value="disabledimage.png"/>
>>>>>                                </DataTrigger>
>>>>>                                <DataTrigger Binding="{Binding ElementName=MyButton,Path=IsEnabled}" Value="true">
>>>>>                                    <Setter Property="Image.Source" Value="enabledimage.png"/>
>>>>>                                </DataTrigger>
>>>>>                            </Style.Triggers>
>>>>>                        </Style>
>>>>>                    </Image.Style>
>>>>>                </Image>
>>>>>            </StackPanel>
>>>>></Button>
(assuming the image files are in the relevant location and have BuildAction = Resource....)
>>>>
>
>Now I see it. Thanks!
>>>>
>>>>WOW. Awesome. Thanks!
>>>
>>>I don't know if you read this before I updated but if so check the current post.
>>> I thought of a way of doing this with just one trigger which is a bit more efficient
>>
>>Ok, I'm not seeing it

Duh. I hadn't posted the update when you replied. Try this instead (more efficient):
<Button x:Name="MyButton">
            <StackPanel>
                <TextBlock>Do Something</TextBlock>
                <Image >
                    <Image.Style>
                        <Style TargetType="Image">
                            <Setter Property="Source" Value ="enabledImage.png"/>
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding ElementName=MyButton,Path=IsEnabled}" Value="false">
                                    <Setter Property="Image.Source" Value="disabledImage.png"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Image.Style>
                </Image>
            </StackPanel>
</Button>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform