gpt4 book ai didi

c# - 堆栈面板内的图像高度

转载 作者:行者123 更新时间:2023-11-30 18:03:37 25 4
gpt4 key购买 nike

我正在 WPF 中设计一个带有滚动查看器和堆栈面板的图片库,如下所示:

<ScrollViewer x:Name="ShopsScroll" Grid.Row="1" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden">
<StackPanel x:Name="stackPanel" Margin="0" Orientation="Horizontal" Height="Auto">
<Image Source="Images/1F/L1_angesb.jpg"/>
<Image Source="Images/1F/L1_chanel.jpg"/>
<Image Source="Images/1F/L1_dior.jpg"/>
<Image Source="Images/1F/L1_gucci.jpg"/>
<Image Source="Images/1F/L1_LV.jpg"/>
<Image Source="Images/1F/L1_nike.jpg"/>
</StackPanel>

由于图像尺寸较大,我想调整它们的大小以适合 StackPanel 的高度。但是,当我将 StackPanel 中的高度值设置为“自动”时,它只是使用图像的高度,而不是其父 ScrollViewer。如果我为 StackPanel 设置一个修复值,问题似乎已解决,但我需要在不同尺寸的屏幕上全屏使用我的应用程序。因此,它应该适应不同的大小而不是硬编码一个固定值。

我该怎么做?

最佳答案

您可以使用元素绑定(bind)将图像的高度绑定(bind)到 StackPanel 元素的高度。抱歉,我现在无法测试此代码,但请尝试类似的方法

<Image Source="Images/1F/L1_nike.jpg" Height="{Binding ElementName=ShopsScroll, Path=Height}" />

参见 MSDN documentation on the Binding.ElementName property .

This property is useful when you want to bind to the property of another element in your application. For example, if you want to use a Slider to control the height of another control in your application, or if you want to bind the Content of your control to the SelectedValue property of your ListBox control.

关于c# - 堆栈面板内的图像高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7062458/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com