0

I am using two button in WPF i want to change their image ie image button on DIsable how to do it can any one help me?

2 Answers 2

2

In WPF an Image button is simply a Button with its Content set to an image. So, if you want to change the image, you simply need to assign another image to the Content property of the Button.

Sign up to request clarification or add additional context in comments.

Comments

0

You cann't change Image, since in WPF Button is just a button as @Daniel Hilgarth wrote. However you can make new style for button like - and apply it to your buttons. This might work like your requirements.

        <Style x:Key="BtnStyle" TargetType="{x:Type Button}">
            <Setter Property="OverridesDefaultStyle" Value="true" />                
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Grid>
                            <!--Image-->
                            <Image x:Name="BtnImage" Stretch="Fill" />
                            <ContentPresenter Margin="2" HorizontalAlignment="Center" RecognizesAccessKey="True" VerticalAlignment="Center" />
                        </Grid>
                        <ControlTemplate.Triggers>
                            <!--Trigger for IsEnabled-->
                            <Trigger Property="IsEnabled" Value="false">
                                <!--Set the source of the image-->
                                <Setter TargetName="BtnImage" Property="Source" Value="pack://application:,,,/YouAppShortName;component/Image.png" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.