【发布时间】:2013-02-16 15:24:15
【问题描述】:
我有一个可以通过 api 设置的图像,我希望图像在其宽度超过 250 像素时被剪裁。那行得通。但是,图像与一些文本块一起位于堆栈面板中。即使我们看到的图像被裁剪,实际图像宽度仍然超过 250 像素。
这里是 xaml
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<Button Foreground="Black" Content="Button" x:Name="BackButton" Style="{StaticResource BackButtonStyle}" Visibility="Collapsed" VerticalAlignment="Center" Margin="25,0,0,0" Click="BackButtonClick" />
<Border>
<Image x:Name="LogoImage" Source="Images/Logo.png" Height="50" Margin="15 0 0 0" Stretch="Uniform" VerticalAlignment="Center">
<Image.Clip>
<RectangleGeometry Rect="0 0 50 250"></RectangleGeometry>
</Image.Clip>
</Image>
</Border>
<TextBlock Foreground="Black" x:Name="NameTextbox" Margin="15, 0, 0, 0" VerticalAlignment="Center" FontSize="26"></TextBlock>
<TextBlock VerticalAlignment="Bottom" x:Name="ErrorMessage" Text="Unable to reach server" Foreground="Red" Margin="15 0 0 0" FontSize="26" FontWeight="Bold" Visibility="Collapsed"></TextBlock>
</StackPanel>
假设图像宽度为 2000 像素。然后图像后面的文本块将被推离屏幕,但只有 250 像素的图像可见。
有什么建议吗?
【问题讨论】:
-
你解决过这个问题吗?我也有同样的问题。
-
是的,我放弃了剪辑并使用了滚动查看器。如果您禁用滚动,那么它会剪切图像并保留您为滚动查看器设置的任何尺寸。我实际上让滚动不可见,以防有人试图滚动他们可以滚动的图像。我粘贴了下面的代码。
标签: c# .net xaml windows-runtime