Reputation: 27575
I am designing a product emulator in WPF. Our company sells a handheld electronic medical device, and we'd like to experiment with user interaction with a "virtual", skinned (sort of) GUI to represent buttons and leds.
Is there a way to "force" WPF to display stuff with its real-world dimension on the screen (by getting monitor dpi information, or something like this)?
As another example, suppose I can layout a plastic, standard-sized Credit Card using WPF controls (DockPanels, Labels, Canvases, etc.), could I consistently display it with the dimensions of a real credit card, across different desktops/laptops?
UPDATE:
I've found a clever way to design in "real milimeters" by using a ViewBox
as the LayoutRoot of my window. Size of anything inside can be "designed in milimeters", and will be displayed in physical size PROVIDED that I can get the right pixel size for the ViewBox. And THAT remain a certain mistery:
Upvotes: 1
Views: 237
Reputation: 27575
I "sort of" solved the problem with the following strategy:
My XAML:
<Window.Resources>
<local:PixelsToMilimeters x:Key="SizeConverter"/>
</Window.Resources>
<Viewbox x:Name="LayoutRoot" Stretch="Uniform"
Width="{Binding Width, ElementName=Case, Converter={StaticResource SizeConverter}}"
Height="{Binding Height, ElementName=Case, Converter={StaticResource SizeConverter}}">
<Border x:Name="Case" Width="108" Height="68">
(...)
My code-behind:
(...)
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return (double)value * (96/25.4);
}
(...)
Of course the "how can I be sure that DPI is actually 96?" is not solved, but that could be encapsulated, and the final result is close enough to the expected one, for my purposes.
Upvotes: 1