Image.FromFile not loading while viewing C # .net design

I'm currently trying to get an image that will be displayed at design time in my Xaml using the code below:

Xaml:

<Canvas Grid.ColumnSpan="2" Margin="0,0,0,0">
    <Image Canvas.ZIndex="1" Source="{Binding Coupon.OverlayImage}"  Margin="0,-21,-76,108" Stretch="Fill" x:Name="PrintImageContextMenu" />
</Canvas>

C # Design Time:

Coupon.OverlayImage = Image.FromFile(@"C:\Temp\Images\TestImage.png");

Original OverlayImage property in VB (Legacy Code):

private _overlayImage as Image

Public Property OverlayImage As Image
    Get
        Return _overlayImage
    End Get
    Set
        _overlayImage = value
        NotifyPropertyChanged("OverlayImage")
    End Set
End Property

At the first view, I see nothing bad, but it does not appear even at runtime. Any ideas would be appreciated.

+4
source share
3 answers

, Image, , System.Drawing.Image, WPF Image FromFile(). WPF. IValueConverter Image BitmapSource/ImageSource.

0

Image Fallback . .

    <Window.Resources>
       <BitmapImage x:Key="ImageSource" UriSource="C:\Temp\Images\TestImage.png"/>
    </Window.Resources>
<Grid>
    <Image
    HorizontalAlignment="Left"
    Source="{Binding SourceImage,FallbackValue={StaticResource ImageSource}}"/>
</Grid>
+1

Try it,

var uri = new Uri(Coupon.OverlayImage);
var bitmap = new BitmapImage(uri);
ImageName.Source = bitmap;
0
source

Source: https://habr.com/ru/post/1618107/


All Articles