Converter:
[Valueconversion (typeof (object), typeof (object)]
Public class dpiconverter: ivalueconverter
{
Public object convert (object value, type targettype, object parameter, cultureinfo Culture)
{
Export winterophelper winhelper = new export winterophelper (mainwindow) app. Current. mainwindow );
Intptr main1_whandle = winhelper. Handle;
Graphics currentgraphics = graphics. fromhwnd (main1_whandle );
Double currentdpix = currentgraphics. dpix;
Double dpixratio = currentdpix/96;
If (targettype = typeof (gridlength ))
{
Double Data = double. parse (parameter. tostring ());
Gridlength = new gridlength (data/dpixratio, gridunittype. pixel );
Return gridlength;
}
If (targettype = typeof (thickness ))
{
Thickness margin = (thickness) parameter;
If (margin! = NULL)
{
Margin. Top = margin. Top/dpixratio;
Margin. Left = margin. Left/dpixratio;
Margin. Right = margin. Right/dpixratio;
Margin. Bottom = margin. Bottom/dpixratio;
Return margin;
}
}
If (targettype = typeof (double ))
{
Double fontsize = double. parse (parameter. tostring ());
Return fontsize/dpixratio;
}
If (targettype = typeof (system. Windows. Point ))
{
System. Windows. Point point = (system. Windows. Point) parameter;
Point. x = point. X/dpixratio;
Point. Y = point. Y/dpixratio;
Return Point;
}
Return NULL;
}
Public object convertback (object value, type targettype, object parameter, cultureinfo Culture)
{
Return NULL;
}
}
Xmal code:
<Image name = "imageicon" stretch = "fill" horizontalalignment = "Left" verticalignment = "TOP"
Width = "{binding converter = {staticresource dpiconverter}, converterparameter = 32 }"
Height = "{binding converter = {staticresource dpiconverter}, converterparameter = 32}">
<Image. margin>
<Binding converter = "{staticresource dpiconverter}">
<Binding. converterparameter>
<Thickness left = "18" Top = "24" Right = "0" Bottom = "48"/>
</Binding. converterparameter>
</Binding>
</Image. margin>
</Image>