Measuring controls created at runtime in WPF

前端 未结 3 478
悲&欢浪女
悲&欢浪女 2021-02-04 05:29

I recognise this is a popular question but I couldn\'t find anything that answered it exactly, but I apologise if I\'ve missed something in my searches.

I\'m trying to c

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-04 05:40

    Solved it!

    The issue was in my XAML. At the highest level of my label's template there was a parent canvas that had no height or width field. Since this did not have to modify its size for its children it was constantly set to 0,0. By removing it and replacing the root node with a border, which must resize to fit its children, the height and width fields are updated and propagated back to my code on Measure() calls.

提交回复
热议问题