I've run into a problem with WPF when I try to use DataBinding with an image as a background to a border. I have no problem rendering the image this way:
<Image Name="imgPlayer" Width="100" Height="100"
Source="{Binding Converter={StaticResource ImageConverter}, Path=Image}"
/>
My DefaultImageConverter just checks if the image is null, and if so, returns a "we have no image" BitmapImage that is an embedded resource in the project. This also works great.
I'm not sure if it's critical but the image is actually coming from a MS SQL Server CE Image field, and the corresponding Entity field is actually a byte array. However, it works just fine.
Then, I decided to try to put a simple rounded border around the image to make it look better. My first attempt was to use a canvas with a border and the image but the square image paints over the rounded parts of the border. After doing some looking, I found you could actually paint an image as the background of the border. This is what I came up with:
<Border Height="100" Width="100" BorderBrush="Gray" CornerRadius="10" BorderThickness="5">
<Border.Background>
<ImageBrush>
<ImageBrush.ImageSource>
<BitmapImage StreamSource="{Binding Converter={StaticResource ImageConverter}, Path=Image}"/>
</ImageBrush.ImageSource>
</ImageBrush>
</Border.Background>
</Border>
My problem is that I am getting an XML parsing error telling me that I have to either set UriSource OR StreamSource. I am setting StreamSource. I have also tried setting UriSource (having found a similar but opposite problem where the same problem was being encountered but using UriSource) and I get the same problem.
It will run, but just fails when it tries to reference this image.
Really I just want to put a rounded border around an image without the image painting over the corners. If there is a totally different way to do this, that works as well.
Hopefully this makes sense!
Regards, Mike