0

I need to change the background image of a button that is declared in xaml, like this:

 <Button x:Name="btnBorder" Content="Moldura" Width="80" Height="80"
         Margin="10,6,10,6"
         Click="btnBorder_Click"
         >
         <Button.Background>
            <ImageBrush ImageSource="/Images/arrow-expand.png" AlignmentX="Center"  Stretch="None" x:Name="imgSourceArrow" />
         </Button.Background>

</Button>

and I'm trying to change the ImageSource of the ImageBrush. For that, I'm using this code in the code-behind:

ImageBrush imgb = new ImageBrush(new BitmapImage(new Uri("/Resources/arrow-expand.png")));
W.btnBorder.Background = imgb;

But when I run the Application, I get an error "UriFormatException was unhandled", "Invalid Uri"...
How can I reference the "arrow-expand.png" image inside the resources and transform it into an Uri String to be passed into the "new Uri" constructor?

My thanks in advanced

2
Contributors
1
Reply
10
Views
3 Years
Discussion Span
Last Post by tinstaafl
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.