在 silverlight 中缩小路径以适应网格?

发布于 2024-11-05 22:26:08 字数 7245 浏览 0 评论 0原文

我有一个画布设置如下:

<Canvas Grid.Column="1" Name="tick"  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="tick" Width="625.75" Height="614.486" Clip="F1 M 0,0L 625.75,0L 625.75,614.486L 0,614.486L 0,0" UseLayoutRounding="False">
                                <Canvas x:Name="Layer_2" Width="625.75" Height="614.486" Canvas.Left="0" Canvas.Top="0">
                                    <Canvas x:Name="Group" Width="630.002" Height="616.107" Canvas.Left="-1.17664" Canvas.Top="-0.438171">
                                        <Path x:Name="Path" Width="145.526" Height="191.479" Canvas.Left="1.61674" Canvas.Top="423.576" Stretch="Fill" Fill="#FFF8F8F8" Data="F1 M 2.24249,423.576C 7.49307,425.327 9.74263,431.733 13.154,436.091C 15.8873,439.583 19.0756,442.697 21.9145,446.103C 32.7198,459.07 43.6481,471.933 54.4535,484.9C 75.4173,510.056 95.8553,535.67 115.503,561.867C 124.758,574.207 133.338,587.124 140.729,600.664C 143.154,605.107 144.567,610.072 147.143,614.43L 2.24249,615.056L 1.61674,614.43L 2.24249,423.576 Z "/>
                                        <Path x:Name="Path_0" Width="626.827" Height="615.164" Canvas.Left="1.12545" Canvas.Top="0.352791" Stretch="Fill" Fill="#FF00B800" Data="F1 M 108.62,340.977C 110.289,341.095 111.957,341.212 113.626,341.329C 115.295,341.447 117.329,340.632 118.632,341.681C 120.441,343.139 120.731,345.827 121.78,347.9C 122.83,349.973 123.576,352.229 124.929,354.118C 128.431,359.01 131.833,363.984 134.941,369.136C 135.843,370.632 137.378,371.639 138.597,372.891C 139.816,374.142 141.325,375.166 142.254,376.645C 149.841,388.724 160.409,399.022 171.821,407.581C 178.232,412.389 185.453,416.769 193.305,418.375C 194.834,418.688 196.364,419.001 197.894,419.313C 199.423,419.626 200.958,420.592 202.482,420.252C 208.089,419.002 209.103,410.82 211.735,405.715C 217.912,393.732 223.858,381.619 230.524,369.901C 250.245,335.235 270.6,300.927 291.386,266.889C 316.703,225.431 344.166,185.23 373.312,146.369C 401.52,108.759 429.274,69.7278 465.102,39.288C 476.756,29.3865 488.046,18.5793 501.591,11.4812C 521.775,0.903687 546.274,0 569.058,0.438171C 578.918,0.627808 588.778,0.817383 598.639,1.00702C 607.812,1.18341 618.298,2.96027 624.863,9.36926C 629.283,13.6833 627.618,21.5565 627.366,27.7272C 627.132,33.4841 629.23,39.8399 626.662,44.9979C 622.944,52.4679 613.913,55.7723 607.342,60.9154C 593.594,71.6764 582.225,85.1784 570.041,97.6826C 542.594,125.851 517.912,156.713 494.473,188.295C 483.079,203.646 470.964,218.612 461.504,235.226C 460.778,236.499 459.444,237.312 458.414,238.355C 457.384,239.397 456.101,240.24 455.324,241.483C 406.922,318.927 357.946,396.555 319.232,479.268C 305.617,508.355 291.001,537.079 279.821,567.186C 276.698,575.597 273.356,583.97 269.164,591.903C 268.672,592.834 268.877,593.989 268.734,595.032C 268.59,596.075 268.649,597.166 268.303,598.161C 266.868,602.294 264.733,606.157 263.206,610.258C 262.611,611.858 262.881,614.173 261.42,615.056C 259.68,616.107 257.354,615.034 255.321,615.023C 253.288,615.012 251.255,615.001 249.222,614.99C 247.189,614.979 245.156,614.968 243.123,614.957C 228.892,614.88 214.661,614.803 200.43,614.726C 188.232,614.661 176.034,614.595 163.836,614.529C 161.803,614.518 159.77,614.507 157.737,614.496C 155.704,614.485 153.671,614.474 151.638,614.463C 149.605,614.452 147.267,615.501 145.539,614.43C 143.726,613.306 143.512,610.676 142.498,608.798C 141.485,606.921 140.471,605.044 139.458,603.167C 135.869,596.52 131.694,590.207 127.744,583.768C 114.001,561.363 97.8589,540.467 81.4389,519.942C 64.5882,498.878 47.396,478.089 30.1275,457.367C 23.1174,448.955 15.9782,440.651 8.85197,432.337C 7.06942,430.257 4.67798,428.761 2.86824,426.705C 2.43244,426.21 2.45108,425.454 2.24249,424.828L 1.61674,424.202C 1.83836,420.031 0,415.187 2.2816,411.687C 3.04422,410.517 4.77156,410.423 6.01655,409.79C 7.26153,409.158 8.64849,408.75 9.75149,407.894C 16.3236,402.792 22.8529,397.608 29.7755,392.993C 30.4704,392.53 31.5835,393.339 32.2785,392.876C 34.2191,391.582 35.3438,389.281 37.2845,387.987C 40.4037,385.907 44.1772,384.943 47.2965,382.864C 56.7196,376.581 65.4063,369.239 74.8294,362.957C 75.5244,362.494 76.6375,363.303 77.3324,362.84C 79.2731,361.546 80.3978,359.245 82.3384,357.951C 85.4577,355.871 89.2312,354.907 92.3504,352.828C 94.2911,351.534 95.4158,349.233 97.3564,347.939C 101.029,345.491 106.136,344.626 108.62,340.977 Z "/>
                                        <Path x:Name="Path_1" Width="536.893" Height="420.98" Canvas.Left="1.61674" Canvas.Top="0.569702" Stretch="Fill" Fill="#FFF8F8F8" Data="F1 M 2.24249,0.569702L 538.51,1.19543C 525.297,4.70508 511.299,7.2359 499.713,14.4926C 462.987,37.4965 433.692,71.506 407.063,105.696C 387.819,130.404 368.141,154.847 350.589,180.786C 346.221,187.242 342.077,193.854 337.527,200.184C 336.703,201.33 335.624,202.27 334.672,203.313C 333.72,204.355 332.524,205.219 331.817,206.441C 321.519,224.255 308.804,240.594 298.457,258.379C 286.183,279.474 273.153,300.121 260.438,320.953C 247.317,342.451 234.983,364.434 223.132,386.657C 218.774,394.83 214.969,403.289 210.643,411.479C 209.909,412.869 209.174,414.26 208.44,415.65C 207.706,417.041 207.387,418.749 206.237,419.822C 202.371,423.428 195.548,420.45 190.385,419.313C 181.181,417.288 172.796,411.822 165.563,405.782C 155.591,397.454 146.73,387.554 139.673,376.645C 138.739,375.201 137.313,374.142 136.133,372.891C 134.954,371.639 133.502,370.597 132.594,369.136C 128.968,363.305 125.303,357.497 121.761,351.615C 119.882,348.495 119.458,343.791 116.168,342.229C 112.062,340.28 107.359,344.973 103.614,347.548C 94.2328,353.997 84.286,359.591 74.8294,365.929C 50.6338,382.147 26.4381,398.364 2.24249,414.581L 1.61674,414.19L 2.24249,0.569702 Z "/>
                                        <Path x:Name="Path_2" Width="367.795" Height="574.438" Canvas.Left="260.677" Canvas.Top="40.6177" Stretch="Fill" Fill="#FFF8F8F8" Data="F1 M 626.467,40.6177C 630.002,64.1845 627.798,88.2671 627.75,112.098C 627.667,153.493 627.584,194.889 627.501,236.285C 627.248,362.542 626.994,488.799 626.741,615.056L 261.303,615.056L 260.677,614.43C 265.518,594.615 274.343,575.972 282.154,557.129C 300.25,513.473 321.398,471.097 343.276,429.208C 390.306,339.164 443.671,251.911 504.798,170.774C 527.125,141.137 551.453,112.832 578.025,86.9329C 588.006,77.2045 596.754,66.0243 607.968,57.7476C 614.73,52.757 622.557,48.0565 626.467,40.6177 Z "/>
                                        <Path x:Name="Path_3" Width="23.7784" Height="15.018" Canvas.Left="603.588" Canvas.Top="0.569702" Stretch="Fill" Fill="#FFF8F8F8" Data="F1 M 626.741,0.569702L 627.366,14.9619L 626.741,15.5877C 626.115,14.9619 625.361,14.4423 624.863,13.7104C 624.211,12.7509 624.17,11.3899 623.338,10.5817C 618.307,5.69745 611.097,3.15491 604.214,1.82117L 603.588,1.19543L 626.741,0.569702 Z "/>
                                    </Canvas>
                                </Canvas>
                                <Canvas x:Name="Layer_3" Width="625.75" Height="614.486" Canvas.Left="0" Canvas.Top="0"/>
                            </Canvas>

我想将其缩小,以便其尺寸适合网格,并且我想通过代码隐藏来做到这一点。网格可以是任意尺寸(其尺寸使用 * 定义)。

I have a canvas set as follows:

<Canvas Grid.Column="1" Name="tick"  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="tick" Width="625.75" Height="614.486" Clip="F1 M 0,0L 625.75,0L 625.75,614.486L 0,614.486L 0,0" UseLayoutRounding="False">
                                <Canvas x:Name="Layer_2" Width="625.75" Height="614.486" Canvas.Left="0" Canvas.Top="0">
                                    <Canvas x:Name="Group" Width="630.002" Height="616.107" Canvas.Left="-1.17664" Canvas.Top="-0.438171">
                                        <Path x:Name="Path" Width="145.526" Height="191.479" Canvas.Left="1.61674" Canvas.Top="423.576" Stretch="Fill" Fill="#FFF8F8F8" Data="F1 M 2.24249,423.576C 7.49307,425.327 9.74263,431.733 13.154,436.091C 15.8873,439.583 19.0756,442.697 21.9145,446.103C 32.7198,459.07 43.6481,471.933 54.4535,484.9C 75.4173,510.056 95.8553,535.67 115.503,561.867C 124.758,574.207 133.338,587.124 140.729,600.664C 143.154,605.107 144.567,610.072 147.143,614.43L 2.24249,615.056L 1.61674,614.43L 2.24249,423.576 Z "/>
                                        <Path x:Name="Path_0" Width="626.827" Height="615.164" Canvas.Left="1.12545" Canvas.Top="0.352791" Stretch="Fill" Fill="#FF00B800" Data="F1 M 108.62,340.977C 110.289,341.095 111.957,341.212 113.626,341.329C 115.295,341.447 117.329,340.632 118.632,341.681C 120.441,343.139 120.731,345.827 121.78,347.9C 122.83,349.973 123.576,352.229 124.929,354.118C 128.431,359.01 131.833,363.984 134.941,369.136C 135.843,370.632 137.378,371.639 138.597,372.891C 139.816,374.142 141.325,375.166 142.254,376.645C 149.841,388.724 160.409,399.022 171.821,407.581C 178.232,412.389 185.453,416.769 193.305,418.375C 194.834,418.688 196.364,419.001 197.894,419.313C 199.423,419.626 200.958,420.592 202.482,420.252C 208.089,419.002 209.103,410.82 211.735,405.715C 217.912,393.732 223.858,381.619 230.524,369.901C 250.245,335.235 270.6,300.927 291.386,266.889C 316.703,225.431 344.166,185.23 373.312,146.369C 401.52,108.759 429.274,69.7278 465.102,39.288C 476.756,29.3865 488.046,18.5793 501.591,11.4812C 521.775,0.903687 546.274,0 569.058,0.438171C 578.918,0.627808 588.778,0.817383 598.639,1.00702C 607.812,1.18341 618.298,2.96027 624.863,9.36926C 629.283,13.6833 627.618,21.5565 627.366,27.7272C 627.132,33.4841 629.23,39.8399 626.662,44.9979C 622.944,52.4679 613.913,55.7723 607.342,60.9154C 593.594,71.6764 582.225,85.1784 570.041,97.6826C 542.594,125.851 517.912,156.713 494.473,188.295C 483.079,203.646 470.964,218.612 461.504,235.226C 460.778,236.499 459.444,237.312 458.414,238.355C 457.384,239.397 456.101,240.24 455.324,241.483C 406.922,318.927 357.946,396.555 319.232,479.268C 305.617,508.355 291.001,537.079 279.821,567.186C 276.698,575.597 273.356,583.97 269.164,591.903C 268.672,592.834 268.877,593.989 268.734,595.032C 268.59,596.075 268.649,597.166 268.303,598.161C 266.868,602.294 264.733,606.157 263.206,610.258C 262.611,611.858 262.881,614.173 261.42,615.056C 259.68,616.107 257.354,615.034 255.321,615.023C 253.288,615.012 251.255,615.001 249.222,614.99C 247.189,614.979 245.156,614.968 243.123,614.957C 228.892,614.88 214.661,614.803 200.43,614.726C 188.232,614.661 176.034,614.595 163.836,614.529C 161.803,614.518 159.77,614.507 157.737,614.496C 155.704,614.485 153.671,614.474 151.638,614.463C 149.605,614.452 147.267,615.501 145.539,614.43C 143.726,613.306 143.512,610.676 142.498,608.798C 141.485,606.921 140.471,605.044 139.458,603.167C 135.869,596.52 131.694,590.207 127.744,583.768C 114.001,561.363 97.8589,540.467 81.4389,519.942C 64.5882,498.878 47.396,478.089 30.1275,457.367C 23.1174,448.955 15.9782,440.651 8.85197,432.337C 7.06942,430.257 4.67798,428.761 2.86824,426.705C 2.43244,426.21 2.45108,425.454 2.24249,424.828L 1.61674,424.202C 1.83836,420.031 0,415.187 2.2816,411.687C 3.04422,410.517 4.77156,410.423 6.01655,409.79C 7.26153,409.158 8.64849,408.75 9.75149,407.894C 16.3236,402.792 22.8529,397.608 29.7755,392.993C 30.4704,392.53 31.5835,393.339 32.2785,392.876C 34.2191,391.582 35.3438,389.281 37.2845,387.987C 40.4037,385.907 44.1772,384.943 47.2965,382.864C 56.7196,376.581 65.4063,369.239 74.8294,362.957C 75.5244,362.494 76.6375,363.303 77.3324,362.84C 79.2731,361.546 80.3978,359.245 82.3384,357.951C 85.4577,355.871 89.2312,354.907 92.3504,352.828C 94.2911,351.534 95.4158,349.233 97.3564,347.939C 101.029,345.491 106.136,344.626 108.62,340.977 Z "/>
                                        <Path x:Name="Path_1" Width="536.893" Height="420.98" Canvas.Left="1.61674" Canvas.Top="0.569702" Stretch="Fill" Fill="#FFF8F8F8" Data="F1 M 2.24249,0.569702L 538.51,1.19543C 525.297,4.70508 511.299,7.2359 499.713,14.4926C 462.987,37.4965 433.692,71.506 407.063,105.696C 387.819,130.404 368.141,154.847 350.589,180.786C 346.221,187.242 342.077,193.854 337.527,200.184C 336.703,201.33 335.624,202.27 334.672,203.313C 333.72,204.355 332.524,205.219 331.817,206.441C 321.519,224.255 308.804,240.594 298.457,258.379C 286.183,279.474 273.153,300.121 260.438,320.953C 247.317,342.451 234.983,364.434 223.132,386.657C 218.774,394.83 214.969,403.289 210.643,411.479C 209.909,412.869 209.174,414.26 208.44,415.65C 207.706,417.041 207.387,418.749 206.237,419.822C 202.371,423.428 195.548,420.45 190.385,419.313C 181.181,417.288 172.796,411.822 165.563,405.782C 155.591,397.454 146.73,387.554 139.673,376.645C 138.739,375.201 137.313,374.142 136.133,372.891C 134.954,371.639 133.502,370.597 132.594,369.136C 128.968,363.305 125.303,357.497 121.761,351.615C 119.882,348.495 119.458,343.791 116.168,342.229C 112.062,340.28 107.359,344.973 103.614,347.548C 94.2328,353.997 84.286,359.591 74.8294,365.929C 50.6338,382.147 26.4381,398.364 2.24249,414.581L 1.61674,414.19L 2.24249,0.569702 Z "/>
                                        <Path x:Name="Path_2" Width="367.795" Height="574.438" Canvas.Left="260.677" Canvas.Top="40.6177" Stretch="Fill" Fill="#FFF8F8F8" Data="F1 M 626.467,40.6177C 630.002,64.1845 627.798,88.2671 627.75,112.098C 627.667,153.493 627.584,194.889 627.501,236.285C 627.248,362.542 626.994,488.799 626.741,615.056L 261.303,615.056L 260.677,614.43C 265.518,594.615 274.343,575.972 282.154,557.129C 300.25,513.473 321.398,471.097 343.276,429.208C 390.306,339.164 443.671,251.911 504.798,170.774C 527.125,141.137 551.453,112.832 578.025,86.9329C 588.006,77.2045 596.754,66.0243 607.968,57.7476C 614.73,52.757 622.557,48.0565 626.467,40.6177 Z "/>
                                        <Path x:Name="Path_3" Width="23.7784" Height="15.018" Canvas.Left="603.588" Canvas.Top="0.569702" Stretch="Fill" Fill="#FFF8F8F8" Data="F1 M 626.741,0.569702L 627.366,14.9619L 626.741,15.5877C 626.115,14.9619 625.361,14.4423 624.863,13.7104C 624.211,12.7509 624.17,11.3899 623.338,10.5817C 618.307,5.69745 611.097,3.15491 604.214,1.82117L 603.588,1.19543L 626.741,0.569702 Z "/>
                                    </Canvas>
                                </Canvas>
                                <Canvas x:Name="Layer_3" Width="625.75" Height="614.486" Canvas.Left="0" Canvas.Top="0"/>
                            </Canvas>

I want to scale it down so that its dimensions fit within the grid and i want to do that through codebehind. The grid can be of arbitrary dimensions (its dimensions are defined using *'s).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

固执像三岁 2024-11-12 22:26:08

您可以将外部 Canvas 包裹在 Viewbox 中,它将根据可用空间按比例调整大小。或者,您可以在 XAML 或代码隐藏中设置 ViewboxWidthHeight,以强制缩放到特定大小。

<Viewbox>
    <!-- your check mark -->
</Viewbox>

You can wrap your outer Canvas in a Viewbox and it will size proportionally to the available space. Alternatively you can set the Width and Height of the Viewbox in XAML or in code-behind to force the scaling to a specific size.

<Viewbox>
    <!-- your check mark -->
</Viewbox>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文