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

Have you tried giving it a literal path instead of a relative path?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.