WPF 路径大小调整

标签 wpf path resize transform

这是我的路径:

<Style x:Key="MyPath" TargetType="{x:Type Path}">
    <Setter Property="SnapsToDevicePixels" Value="true" />                                    
    <Setter Property="Stroke" Value="Blue" />               
    <Setter Property="Data" Value="M0,100 L 80,40 160,100 M 40,80 L 40,160 120,160 120,80" />
</Style>


<Path Style="{StaticResource MyPath}">
    <Path.RenderTransform>
        <ScaleTransform ScaleX="0.3"
                        ScaleY="0.3" />
    </Path.RenderTransform>
</Path>

这会缩放图像,这很好。

问题是路径周围的空白区域(大小与原始路径大小相同)在缩放后仍然可见。设置路径的宽度和高度并不能解决问题,因为例如设置高度会导致图像被剪切,但空白区域仍然存在。

为了清楚起见,我添加了一张图片:

alt text http://img190.imageshack.us/img190/5923/problemis.png

有什么帮助吗?谢谢

最佳答案

尝试使用 LayoutTransform 而不是 RenderTransform。

ScotLogic blog - LayoutTransform vs. RenderTransform

“应用 LayoutTransform 时,相邻元素会重新定位以适应转换后的元素,而使用 RenderTransform 则不会。”

关于WPF 路径大小调整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2235024/

相关文章:

image - 如何在 Octave 中调整/缩放图像大小?

c# - 在 WPF 中指定 WrapPanel 的最大列数

c# - 将 wpf 进度条与库中的函数同步的正确方法

java - Flutter Java android从/app_flutter文件夹中的文件获取数据

php - 错误 :- php is not recognised as an internal or external command

css - 调整窗口大小时如何裁剪图像并保持其居中

c# - 使 WPF Tabcontrol 标题垂直堆叠

c# - 在嵌套 Parallel.For 循环中使用 WriteLine 时出现 IndexOutofRangeException

json - 如何使用 jq 将项目映射到 json 结构中?

JQuery - 删除调整大小功能