dinesh
dinesh

Reputation: 229

how to change image button image when we click on button in silverlight?

I have one image button in Silverlight in initial load it will show demo1 image, whenever I click on that button i should change image to demo2.

<Button x:Name="demo"
        IsEnabled="False"
        Click="demo_Click"
        ToolTipService.ToolTip="demo"
        Width="25"
        Height="25"
        VerticalAlignment="Bottom"
        HorizontalAlignment="Left" 
        Margin="0,0,0,25">

    <Image x:Name="demo-image" Source="/demo.content;component/demo1.png"/>

</Button>

Upvotes: 0

Views: 1748

Answers (2)

Misha
Misha

Reputation: 571

You can use a ToggleButton instead

Upvotes: 0

Anders Gustafsson
Anders Gustafsson

Reputation: 15971

First of all, remove IsEnabled="False" from the Button XAML. Then simply implement the demo_Click event handler in your code-behind as follows:

private void demo_Click(object sender, RoutedEventArgs e)
{
    demo_image.Source = new BitmapImage(
        new Uri("/demo.content;component/demo2.png", UriKind.Relative));
}

Upvotes: 1

Related Questions