你可以嘗試創建一個Converter
返回乘以無論你DLU值
例如,我創建了一個MathConverter
(代碼爲here),這將讓你指定一個像
<Button Height="{Binding Source={x:Static local:Settings.VerticalDLU,
Converter={StaticResource MathConverter},
[email protected]*14}"
Width="{Binding Source={x:Static local:Settings.HorizontalDLU,
Converter={StaticResource MathConverter},
[email protected]*50}" />
東西爲了使寫和讀更容易,您可以創建一個繼承自「綁定」並設置默認綁定屬性的類,因此您所要做的只是
<Button Height="{local:MyVDluBinding Source=14}"
Width="{local:MyHDluBinding Source=50}" />
我從來沒有嘗試覆蓋默認值爲Converter
和ConverterParameter
的綁定,但爲了驗證目的我已經覆蓋了一個綁定,所以我相信這是可能的。
我創建的ValidationBinding
可以像Text="{local:ValidationBinding MyProperty}"
一樣使用,並在綁定中自動設置ValidatesOnDataError=True, ValidatesOnException=True, UpdateSourceTarget=PropertyChanged
。
重複的http://stackoverflow.com/questions/395195/wpf-how-to-specify-units-in-dialog-units – Bas
@Bas就好像我鏈接到它不是一個贈品。 –
可能重複的[WPF:如何在對話單元中指定單位?](https://stackoverflow.com/questions/395195/wpf-how-to-specify-units-in-dialog-units) –