I have a user control in which I want to set the background image. If I do that, it works:
The view:
<UserControl.Background>
<ImageBrush AlignmentX="Center" AlignmentY="Center" Stretch="Uniform" Opacity="0.25" ImageSource="{Binding Logo}">
<ImageBrush.RelativeTransform>
<ScaleTransform ScaleX="0.75" ScaleY="0.75" CenterX=".5" CenterY="0.5" />
</ImageBrush.RelativeTransform>
</ImageBrush>
</UserControl.Background>
The property in the view model:
private byte[] _logo = GlobalVariables.Logo;
public byte[] Logo
{
get { return _logo; }
set
{
_logo = value;
base.RaisePropertyChangedEvent("Logo");
}
}
Really I load the logo in a global variable when I start the application, because the logo is stored in the database and in this way I only have to load once, not each time I want to print a document.
So it is a global variable, I am trying to get the logo directly from the global variables, so I can avoid the needed to have a property in my view model.
So in my view I am trying this code:
<UserControl.Background>
<ImageBrush AlignmentX="Center" AlignmentY="Center" Stretch="Uniform" Opacity="0.25" ImageSource="{x:Static vg:GlobalVariables.Logo}">
<ImageBrush.RelativeTransform>
<ScaleTransform ScaleX="0.75" ScaleY="0.75" CenterX=".5" CenterY="0.5" />
</ImageBrush.RelativeTransform>
</ImageBrush>
</UserControl.Background>
In this case, I get the following error:
'System.Byte[]' no es un valor válido para la propiedad 'ImageSource'.
I don't understand why, because in the example that works, the property in my view model is also a Byte[], in fact, in my view model I am setting the glbal variable to the property.
Thanks.