【问题标题】:How to constrain the width and height of <Border> element to be equal to its inner contents?如何约束 <Border> 元素的宽度和高度等于其内部内容?
【发布时间】:2012-04-09 15:50:45
【问题描述】:
<Grid x:Name="mainGrid">
                <Border BorderBrush="Black">
                        <Grid Name="detailGrid">

这里,detailGrid 及其border 具有完整的宽度和高度,可从外部mainGrid 获得,而detailGrid 内部的内容的宽度和高度要小得多。

如何限制Border 或/和detailGrid 的宽度和高度以适应其内容,以便外部网格的背景可见?

【问题讨论】:

  • 尝试在detailgrid下移动边框元素

标签: wpf xaml silverlight-4.0


【解决方案1】:

将边框和内部网格HorizontalAlignmentVerticalAlignment 设置为Center。 (或者只是边框应该这样做)

【讨论】:

  • 该死,我早该知道 :-)
【解决方案2】:

如果您的用户控件定义了HeightWidth 属性,请将它们删除。

然后为您的Grid 定义ColumnDefinitionsRowDefinitions 并将它们的HeightWidth 设置为Auto

【讨论】:

    猜你喜欢
    • 2013-02-16
    • 2015-11-02
    • 1970-01-01
    • 1970-01-01
    • 2018-03-30
    • 1970-01-01
    • 1970-01-01
    • 2019-11-24
    相关资源
    最近更新 更多