[UWP]如何测量UIElement [英] [UWP] How to Measure an UIElement

查看:73
本文介绍了[UWP]如何测量UIElement的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我将一个UIElement添加到Canvas /Canvas.Children.Add(uiElement)/。

Hello I add an UIElement to a Canvas /Canvas.Children.Add(uiElement)/.

接下来,我想知道添加了什么宽度和高度UIElement

Next, I want to know what width and height added UIElement has.

如何获取这些数据?

推荐答案

您好, 

Hello, 

最简单的方式是订阅您的UIElement加载事件并获取其ActualWidth和ActualHeigth。另一种情况是,如果您的画布已经渲染,那么您可以执行此操作  

on of the simplest way it to subscribe on your UIElement loaded event and get their ActualWidth and ActualHeigth. The other is if your canvas is already rendered then you can do this  

            UIElement button = new Button();
            canvas.Children.Add(button);
            button.Measure(canvas.RenderSize);
            var t = button.DesiredSize;


这篇关于[UWP]如何测量UIElement的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆