[UWP] XAML布局错误 [英] [UWP]XAML Layout bug

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

问题描述

大家好,

创建自定义XAML面板时,布局出现问题。如果在MeasureOverride传递中,使用double.PositiveInfinite测量元素,然后在ArrangeOverride中安排的值小于元素的DesiredSize,
则Arrange不起作用并剪切元素。

When creating a custom XAML panel, there is a problem in the layout. If in the MeasureOverride pass an element is measured with double.PositiveInfinite and then in the ArrangeOverride is arranged with a value that is smaller than the DesiredSize of the element, the Arrange doesn't work and clips the element.

public class MyPanel : Panel
{
    protected override Size MeasureOverride(Size availableSize)
    {
        foreach (var child in Children)
        {
            child.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
        }
        return new Size();
    }

    protected override Size ArrangeOverride(Size finalSize)
    {
        foreach (var child in Children)
        {
            child.Arrange(new Rect(0, 0, 30, 30));
        }
        return finalSize;
    }
}




myPanel.Children.Add(
    new Border
    {
        BorderThickness = new Thickness(1),
        BorderBrush = new SolidColorBrush(Colors.Black),
        Child = new TextBlock { Text = "Some long test whose size is grater than the arrange size" }
    });

结果是一个剪切元素。请注意,Border元素的右边框应该是可见的。

The result is a clipped element. Notice the right border of the Border element should be visible.

这个错误使得创建面板变得相当困难,并且任何解决方法都可能带来布局周期,这种可怜的错误已存在多年。请修好!!!!!!!!

This bugs makes rather difficult to create panels, and any workaround can bring layout cycles, this pathetic error is been there for years. Please fix it!!!!!!!!

问候,

Alvaro。

Alvaro Rivoir

Alvaro Rivoir

推荐答案

您好Alvaro,

Hello Alvaro,

欢迎来到开发通用Windows应用论坛! 

请阅读粘性帖子,尤其是  发布指南:主题行标签 &absp; 已知的
Windows 10 SDK和工具的问题 

Please read the sticky posts, especially the Guide to posting: subject line tags and Known Issues for Windows 10 SDK and Tools .

我们需要标签来了解项目类型,所以在这里我将你的标题编辑为UWP。

We need tags to know project types so here I edit your title as UWP.

感谢你报告这个,我可以重现同样的用你的代码。但我不确定这种行为是由于代码还是需要报告。所以,我正在尝试为您咨询此案例。请稍等。

And thank you for reporting this,I can reproduce the same with your code. But I'm not so sure whether this behavior is due to code or it need to be reported. So I'm trying to consult this case for you. Please wait a few moments.

致以最好的问候,

Barry


这篇关于[UWP] XAML布局错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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