Search code examples
c#wpfxamlwindows-phone-8.1windows-phone-silverlight

Programmatically change button image source WPSL 8.1


This is my xaml:

<Button x:Name="FlashButton"
        BorderThickness="0"
        Click="FlashButton_Click">
<Button.ContentTemplate>
    <DataTemplate>
        <Grid Width="70"
              Height="70">
            <Ellipse Stroke="White" 
                     StrokeThickness="3"/>
            <Image x:Name="FlashButtonImage" 
                   Source="/Assets/Images/flashOn.png" />
        </Grid>
    </DataTemplate>
</Button.ContentTemplate>

It creates a circle button with a flash image in it. When I press the button I want to change FlashButtonImage source to "/Assets/Images/flashOn.png" but I can't access the image inside it. Is it a simple way to design this type of button or you can help me with some code for accessing image source?


Solution

  • You should try this code instead:

    <Button x:Name="FlashButton"
            BorderThickness="0"
            Click="FlashButton_Click">
        <Grid Width="70"
              Height="70">
            <Ellipse Stroke="White" 
                     StrokeThickness="3"/>
            <Image x:Name="FlashButtonImage" 
                   Source="/Assets/Images/flashOn.png" />
        </Grid>
    </Button>