WPF Units and Code-Behind

后端 未结 2 1793
不思量自难忘°
不思量自难忘° 2021-02-19 09:31

Recently I discovered WPF supports different measurement units in XAML. Besides default DIPs, there is also support for pixels, inches and centimeters (as far as I know). This a

2条回答
  •  野性不改
    2021-02-19 10:21

    For 1) and 2) Because DIPs are device independent, you can calculate any "natural unit" to and from without problems. The exception are (unnatural :) device dependent pixels.

    Create a ValueConverter that converts string values to doubles where your desired units may be specified in the string. Then you can use the ValueConverter in your Binding and calculate in your ViewModel in "natural units".

    For 3) and the implementation: I have quickly googled and found nothing, but maybe will a deeper search show something. Otherwise, creating your own converter should not be very difficult. Here some conversion infos:

    96DIP == 1inch == 2.54cm;
    1cm == 37.8DIP;
    1zoll == 1inch == 2.54cm;
    

提交回复
热议问题