wpf - WPF - 确定动态创建的控件是否适合容器
问题描述
动态创建控件有没有办法检查它是否适合像网格列这样指定的容器MaxWidth
?
我目前的解决方案是将控件添加到容器中,等待布局更新然后检查该控件的总宽度是否大于容器的宽度。
//Code inside Window's metod
var checkbox = new CheckBox
{
Content = "Some content"
};
ButtonBarOption.Children.Add(checkbox);
UpdateLayout();
if (ButtonBarOption.ActualWidth > ButtonBarOptionColumn.MaxWidth)
{
ButtonBarOption.Children.Remove(checkbox);
OptionsContainer.Children.Add(checkbox);
}
就像上面的例子一样,当控件不适合容器时,我将它重新定位到不同的地方。
解决方案
推荐阅读
- firebase - 更新后无法写入 Firestore(颤振)
- java - 如何将搜索友好数字的实现从命令式转移到功能性?
- mysql - 如何从 Laravel 项目中删除所有迁移但保留表和字段
- javascript - 我正在尝试为 Google Sign-in api 调用 signOut() 函数,但不断收到错误“未定义 gapi”
- sql - 创建一个包含返回记录的存储过程
- php - 刀片中的 Laravel 5.8 在 @php 指令中看不到来自 @foreach 的变量
- spring-boot - 如何使用 resttemplate 和 springboot 捕获自定义异常?
- linux - 我正在编辑我的 .bashrc 文件以备份历史记录,但它没有按预期工作
- c++ - gcc vs clang:静态转换时在未使用的模板专业化中解析了 noexcept
- mule4 - 有没有人在 Mule 4, Anypoint studio 7.3.2 中遇到过这个错误 - “执行脚手架时出错”