1

I made WinForm project and add ElementHost for using WPF blend effect on some Images.

ElementHost m_host = new ElementHost();
WPF_TK4S wpfTK4S = new WPF_TK4S();
m_host.Child = wpfTK4S;
m_host.Size = new Size(1000, 1000);
m_host.Location = new Point(0, 0);
this.Controls.Add(m_host);

I added the image control on WPF user control like below.

<UserControl x:Class="Test.WPF_TK4S"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         mc:Ignorable="d" 
         d:DesignHeight="1000" d:DesignWidth="1000">
<Grid>
    <Grid.Background>
        <ImageBrush/>
    </Grid.Background>
    <Image Source="/Resources/TK4S_254X253.png" HorizontalAlignment="Left" Height="344" Margin="48,44,0,0" VerticalAlignment="Top" Width="342" Stretch="None"/>
</Grid>

The image is shown well on control view but is now shown when I run the application. Fortunately, after I changed the source uri into absolute uri like

"D://Visual Project/Test/Test/Resources/TK4S_254X253.png"

the image is shown well!! I tried to use all kinds of relative uri like

".../Test/Resources/TK4S_254X253.png", "pack://application:,,,/TK4S_254X253.png" 

but it is not work. I need to use relative path because the project is operating on Server so every project paths are different. And I have to use this things on xaml because I have to use blend after the image is initialized. Does anything I need to know other option?

KimSJ
  • 133
  • 4
  • Did you try `Source="./Resources/TK4S_254X253.png"`? It should work, provided that it is a valid relative path. – Clemens Apr 18 '18 at 08:31
  • Possible duplicate of [WPF image resources](https://stackoverflow.com/questions/347614/wpf-image-resources) – ASh Apr 18 '18 at 08:32
  • Sure. But It does not work. It is naturally well on WPF project but It seems like It is not recognize the relative path on winform project using wpf host control. – KimSJ Apr 18 '18 at 08:34
  • [How to get a System.Drawing.Image object from image which build action is marked as Resource?](https://stackoverflow.com/q/32486679/3110834) – Reza Aghaei Apr 18 '18 at 08:35

0 Answers0