容器自动调整为固定大小的元素

时间:2021-04-19 21:39:33

I have a RelativePanel with a fixed size element (in this case a TextBlock). This RelativePanel also has two Image elements with no Height/Width explicitly set, but set to stretch. What I want is that the RelativePanel (or some other container) adjusts its size to accommodate the TextBlock and then have the Images scale to fill the space that's left for them.

我有一个具有固定大小元素的RelativePanel(在本例中是一个TextBlock)。此RelativePanel还有两个Image元素,没有明确设置Height / Width,但设置为stretch。我想要的是RelativePanel(或其他一些容器)调整其大小以容纳TextBlock,然后使用Images缩放来填充剩下的空间。

The RelativePanel is arranged horizontally, going like (generic example):

RelativePanel水平排列,就像(通用示例):

<RelativePanel Height="80">
    <Image Source="..."/>
    <TextBlock Text="..."/>
    <Image Source="..."/>
</RelativePanel>

What would be a good way to accomplish this?

什么是实现这一目标的好方法?

Edit: Image of what I want

编辑:我想要的图像

1 个解决方案

#1


0  

Images control has Stretch="UniformToFill" property that will display image in available space.

图像控件具有Stretch =“UniformToFill”属性,该属性将在可用空间中显示图像。

Can you try with this

你能尝试一下吗?

<RelativePanel x:Name="mainPanel" Height="80">
    <Image x:Name="Img1" Source="..." Stretch="UniformToFill"/>
    <TextBlock x:Name="TxtBlock1" Text="..."/ RelativePanel.AlignLeftWith="Img1" Width=150>
    <Image x:Name="Img2" Source="..." Stretch="UniformToFill" RelativePanel.AlignLeftWith="TxtBlock1"/></RelativePanel>

#1


0  

Images control has Stretch="UniformToFill" property that will display image in available space.

图像控件具有Stretch =“UniformToFill”属性,该属性将在可用空间中显示图像。

Can you try with this

你能尝试一下吗?

<RelativePanel x:Name="mainPanel" Height="80">
    <Image x:Name="Img1" Source="..." Stretch="UniformToFill"/>
    <TextBlock x:Name="TxtBlock1" Text="..."/ RelativePanel.AlignLeftWith="Img1" Width=150>
    <Image x:Name="Img2" Source="..." Stretch="UniformToFill" RelativePanel.AlignLeftWith="TxtBlock1"/></RelativePanel>