WPF - 为Canvas设置不同的大小

时间:2016-06-25 04:19:58

标签: .net wpf canvas path resize

我正在为我的所有图标使用ResourceDictionary:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                            xmlns:local="clr-namespace:SCL_Resources">
            <Canvas x:Key="Folder_2" Width="164.514" Height="123.9186" Canvas.Left="0" Canvas.Top="0">
                <Path Width="149.363" Height="41.136" Canvas.Left="8.05786" Canvas.Top="7.85583" Stretch="Fill" Fill="{DynamicResource color_Folderback}" Data="M 12.9552,7.85583L 152.523,7.85583C 155.229,7.85583 157.421,10.0479 157.421,12.7532L 157.421,44.0945C 157.421,46.7998 155.229,48.9919 152.523,48.9919L 12.9552,48.9919C 10.2499,48.9919 8.05786,46.7998 8.05786,44.0945L 8.05786,12.7532C 8.05786,10.0479 10.2499,7.85583 12.9552,7.85583 Z "/>
                <Path Width="45.9107" Height="15.8546" Canvas.Left="8.01707" Canvas.Top="0" Stretch="Fill" Fill="{DynamicResource color_Folderback}" Data="M 13.1491,0L 49.0611,0C 51.7664,0 53.9277,2.37598 53.9277,5.0813L 53.9277,10.9573C 53.9277,13.6627 51.7357,15.8546 49.0304,15.8546L 13.1184,15.8546C 10.4144,15.8546 8.01707,13.6627 8.01707,10.9573L 8.01707,5.0813C 8.01707,2.37598 10.4437,0 13.1491,0 Z "/>
                <Path Width="164.514" Height="105.289" Canvas.Left="0" Canvas.Top="18.6296" Stretch="Fill" Fill="{DynamicResource color_Floderfront}" Data="M 4.972,18.6296L 159.528,18.6296C 162.421,18.6296 164.647,20.9723 164.5,23.8522L 159.615,119.327C 159.485,121.866 157.188,123.919 154.483,123.919L 10.0173,123.919C 7.31199,123.919 5.01467,121.866 4.88533,119.327L 0,23.8522C -0.146667,20.9723 2.07867,18.6296 4.972,18.6296 Z "/>
            </Canvas>
</ResourceDictionary>

实际XAML:

<ContentControl Height="15" Width="20" Content="{DynamicResource Folder_2}"/>

<ContentControl Height="60" Width="80" Content="{DynamicResource Folder_2}"/>

这不是很好,它在外面溢出。

有没有办法设置DynamicResource的大小或其他任何聪明的事情?

提前致谢。

1 个答案:

答案 0 :(得分:0)

您的CanvasPath(s)ContentControl的宽度不匹配。

所以,把所有内容都放在ViewBox之内:

<Viewbox x:Key="Folder_2"> <Canvas> ... </Canvas></Viewbox>