开发者

Setting a custom control's aspect ratio

开发者 https://www.devze.com 2022-12-16 04:46 出处:网络
Is there a way, using XAML (and possibly Template Bindings) to keep a control\'s width in a certain proportion to its height? I would like for my control, at design tim开发者_如何学运维e in Blend, to

Is there a way, using XAML (and possibly Template Bindings) to keep a control's width in a certain proportion to its height? I would like for my control, at design tim开发者_如何学运维e in Blend, to always scale evenly.


Code like the following is working fine for me. I had been looking for a more WPF-ish template-based approach, but I suppose there's nothing wrong with the classic approach. This goes in the constructor of the control:

SizeChanged += ( s, e ) => Width = e.NewSize.Height * .5;
0

精彩评论

暂无评论...
验证码 换一张
取 消