私はこれでしばらく頭を傷つけてきました。私はそれが実際のサイズ(またはメインウィンドウ自体よりも大きくない高さ)だ時にツールチップのイメージが画像をポップアップする必要があり持っている私のメインウィンドウでWPF Image to ToolTip - DPIの問題
:
<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>
(メインウィンドウのx:名前 'はMW ')別のクラスにおいて
は、他の場所で、私はこのイメージコントロールにBitmapImageのをロードしています:
Image img = (Image)mw.FindName("ss1");
img.Source = GetBitmapImageFromDisk(path, UriKind.Absolute);
そしてGetBitMapImageFromDisk方法:
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;
}
}
画像のツールチップがマウスでポップアップしますが、画像のサイズが画像自体のDPIに依存するように見えるという問題があります。だから何らかの理由でDPIが '762'と言う画像をターゲットにしているのであれば、ツールヒントの画像は表示されたときに非常に小さくなります。
誰も私の現在のコードでこれを緩和する方法を提案できますか?実行時にロードされるイメージは、ほとんどすべてのサイズ、DPI、およびアスペクト比になります。
おそらく役に立ちます:http://stackoverflow.com/a/644625/1136211 – Clemens