【问题标题】:How to show images with equal size in a Viewbox?如何在 Viewbox 中显示相同大小的图像?
【发布时间】:2016-07-25 12:29:57
【问题描述】:

我有以下代码:

<StackPanel Orientation="Vertical">
    <Viewbox Height="100" >

        <Canvas x:Name="pluginTile" Style="{StaticResource productImageTopFade}" Width="320" Height="200">
            <Image Panel.ZIndex="1" Source="{Binding PluginImagePath}" Margin="0,10,15,0"  ></Image>
            <Canvas.Effect>
                <DropShadowEffect ShadowDepth="2" Opacity="0.15" Direction="270" BlurRadius="20" />
            </Canvas.Effect>
         </Canvas>
    </Viewbox>
    <Border BorderBrush="Transparent" BorderThickness="1">
        <Label FontWeight="Normal" Name="ProductName"  Content="{Binding NameAndEdition}" Margin="0 0 0 0" VerticalAlignment="Bottom" HorizontalAlignment="Center" Foreground="Gray"   />
    </Border></StackPanel>

我想要在视图框中显示不同尺寸的图像,上面提到的代码是 ListBox 的 ItemContainerStyle 的一部分。 问题是我在列表框中得到了不同尺寸的图像,其中一些被剪切,而一些尺寸缩小,有什么方法可以显示这些尺寸相同的图像?

【问题讨论】:

标签: c# wpf xaml listbox wpf-controls


【解决方案1】:

您需要将Stretch="FiLL" 属性添加到您的图像中。

【讨论】:

  • 我已经尝试过了,通过设置该属性,它开始与视图框外的标签文本重叠。不知道为什么
  • @Sameed 我们能看一下你的意思吗?
【解决方案2】:

我使用了网格面板而不是画布,它解决了这个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-10
    • 2021-03-13
    • 1970-01-01
    相关资源
    最近更新 更多