I've been scratching my head for a while with this.
On my MainWindow I have an an Image who's ToolTip should pop up the image at it's actual size (or with a height no larger than the MainWindow itself):
<Image x:Name="ss1" Grid.Column="0" Grid.Row="0" Margin="0">
<Image.ToolTip>
<ToolTip DataContext="{Binding PlacementTarget, RelativeSource={RelativeSource Self}}">
<Border BorderBrush="Black" BorderThickness="1" Margin="5,7,5,5">
<Image Source="{Binding Source}" MaxHeight="{Binding ElementName=MW,Path=Height}" Stretch="Uniform" ToolTipService.Placement="Top"/>
</Border>
</ToolTip>
</Image.ToolTip>
</Image>
(MainWindow's x:name is 'MW')
In another class elsewhere I am loading a BitmapImage into this image control:
Image img = (Image)mw.FindName("ss1");
img.Source = GetBitmapImageFromDisk(path, UriKind.Absolute);
And the GetBitMapImageFromDisk method:
public static BitmapImage GetBitmapImageFromDisk(string path, UriKind urikind)
{
if (!File.Exists(path))
return null;
try
{
BitmapImage b = new BitmapImage(new Uri(path, urikind));
return b;
}
catch (System.NotSupportedException ex)
{
BitmapImage c = new BitmapImage();
return c;
}
}
The image ToolTip pops up on mouse over but the problem is that the size of the image appears to be dependent on the DPI of the image itself. So if for some reason it targets an image who's DPI is say '762' the ToolTip image is really tiny when it is displayed.
Can anyone suggest a way of mitigating this with my current code? The images that are loaded at runtime can be pretty much any size, DPI and aspect ratio.