none
有一个Path的data(字符串),如何用代码在Silverlight里使用? RRS feed

  • 问题

  • 比如,有一个路径的data为
    F1M8.92578125,10.314453125L10.41015625,10.802734375 7.5,17.482421875 6.03515625,16.837890625 8.92578125,10.314453125z M16.77734375,10.236328125L18.2080078125,13.2001953125 19.765625,16.623046875 18.28125,17.306640625 15.41015625,10.841796875 16.77734375,10.236328125z M12.2265625,7.423828125L13.75,7.423828125 13.75,17.736328125 13.1494140625,19.7041015625 11.34765625,20.333984375 8.7890625,20.314453125 8.4765625,18.634765625 10.9375,18.791015625 11.904296875,18.478515625 12.2265625,17.462890625 12.2265625,7.423828125z M9.8828125,1.38867175579071L11.38671875,1.95507824420929 10.283203125,4.513671875 19.35546875,4.513671875 19.35546875,6.134765625 17.9296875,9.572265625 16.5234375,9.044921875 17.7734375,5.998046875 9.560546875,5.998046875 7.578125,9.357421875 6.3671875,8.361328125 8.369140625,5.01660108566284 9.8828125,1.38867175579071z M4.98046875,1.33007800579071L6.58203125,1.79882800579071 4.7265625,6.37890625 4.7265625,20.548828125 3.203125,20.548828125 3.203125,9.328125 0.91796863079071,12.755859375 0.25390625,11.037109375 2.998046875,6.4814453125 4.98046875,1.33007800579071z M23.916015625,6.955078125L23.26904296875,10.1630859375 22.71484375,12.326171875 24.78515625,13.95703125 25.83984375,10.84423828125 26.3671875,6.955078125 23.916015625,6.955078125z M28.5546875,2.716796875L38.92578125,2.716796875 38.92578125,4.259765625 34.765625,7.794921875 34.765625,10.158203125 39.7265625,10.158203125 39.7265625,11.583984375 34.765625,11.583984375 34.765625,17.833984375 34.1357421875,19.62109375 32.24609375,20.216796875 31.1962890625,20.20703125 29.6875,20.177734375 29.43359375,18.595703125 30.9619140625,18.7177734375 32.03125,18.771484375 32.9248046875,18.4833984375 33.22265625,17.619140625 33.22265625,11.583984375 27.8515625,11.583984375 27.8515625,10.158203125 33.22265625,10.158203125 33.22265625,7.111328125 36.7578125,4.142578125 28.5546875,4.142578125 28.5546875,2.716796875z M23.26171875,1.36914074420929L24.84375,1.58398425579071 24.1796875,5.490234375 27.87109375,5.490234375 27.87109375,6.759765625 27.1728515625,11.45458984375 25.95703125,14.89453125 28.515625,16.994140625 27.36328125,18.224609375 25.166015625,16.22265625 23.46435546875,18.35400390625 21.2890625,20.314453125 20.390625,19.044921875 22.47314453125,17.25048828125 24.072265625,15.24609375 21.1328125,12.736328125 21.806640625,10.05078125 22.421875,6.955078125 20.3515625,6.955078125 20.3515625,5.490234375 22.666015625,5.490234375 23.26171875,1.36914074420929z
    如果在 xmal 中,可以用 

     <Path Data="F1M8.92578125,10.314453125L10.41015625,10.802734375 7.5,17.482421875 6.03515625,16.837890625 8.92578125,10.314453125z M16.77734375,10.236328125L18.2080078125,13.2001953125 19.765625,16.623046875 18.28125,17.306640625 15.41015625,10.841796875 16.77734375,10.236328125z M12.2265625,7.423828125L13.75,7.423828125 13.75,17.736328125 13.1494140625,19.7041015625 11.34765625,20.333984375 8.7890625,20.314453125 8.4765625,18.634765625 10.9375,18.791015625 11.904296875,18.478515625 12.2265625,17.462890625 12.2265625,7.423828125z M9.8828125,1.38867175579071L11.38671875,1.95507824420929 10.283203125,4.513671875 19.35546875,4.513671875 19.35546875,6.134765625 17.9296875,9.572265625 16.5234375,9.044921875 17.7734375,5.998046875 9.560546875,5.998046875 7.578125,9.357421875 6.3671875,8.361328125 8.369140625,5.01660108566284 9.8828125,1.38867175579071z M4.98046875,1.33007800579071L6.58203125,1.79882800579071 4.7265625,6.37890625 4.7265625,20.548828125 3.203125,20.548828125 3.203125,9.328125 0.91796863079071,12.755859375 0.25390625,11.037109375 2.998046875,6.4814453125 4.98046875,1.33007800579071z M23.916015625,6.955078125L23.26904296875,10.1630859375 22.71484375,12.326171875 24.78515625,13.95703125 25.83984375,10.84423828125 26.3671875,6.955078125 23.916015625,6.955078125z M28.5546875,2.716796875L38.92578125,2.716796875 38.92578125,4.259765625 34.765625,7.794921875 34.765625,10.158203125 39.7265625,10.158203125 39.7265625,11.583984375 34.765625,11.583984375 34.765625,17.833984375 34.1357421875,19.62109375 32.24609375,20.216796875 31.1962890625,20.20703125 29.6875,20.177734375 29.43359375,18.595703125 30.9619140625,18.7177734375 32.03125,18.771484375 32.9248046875,18.4833984375 33.22265625,17.619140625 33.22265625,11.583984375 27.8515625,11.583984375 27.8515625,10.158203125 33.22265625,10.158203125 33.22265625,7.111328125 36.7578125,4.142578125 28.5546875,4.142578125 28.5546875,2.716796875z M23.26171875,1.36914074420929L24.84375,1.58398425579071 24.1796875,5.490234375 27.87109375,5.490234375 27.87109375,6.759765625 27.1728515625,11.45458984375 25.95703125,14.89453125 28.515625,16.994140625 27.36328125,18.224609375 25.166015625,16.22265625 23.46435546875,18.35400390625 21.2890625,20.314453125 20.390625,19.044921875 22.47314453125,17.25048828125 24.072265625,15.24609375 21.1328125,12.736328125 21.806640625,10.05078125 22.421875,6.955078125 20.3515625,6.955078125 20.3515625,5.490234375 22.666015625,5.490234375 23.26171875,1.36914074420929z"
            Fill="Red"></Path>
    来指定。

    问题是,我如何用c#代码,把已知的data的字符串值,定义为一个path的data属性? 

    谢谢

    2009年8月31日 11:44

答案

  • Xaml:

    <Path x:Name="Path1" Data="{Binding ElementName=Path1, Path=Tag}" Fill="Red"/>

    ------------------------------

    C#:

    Path.Tag = "F1 M8.92578125,10.314453125L10.41015625,10.802734375 7.5,17.482421875 6.03515625,16.837890625 8.92578125,10.314453125z M16.77734375,10.236328125L18.2080078125,13.2001953125 19.765625,16.623046875 18.28125,17.306640625 15.41015625,10.841796875 16.77734375,10.236328125z M12.2265625,7.423828125L13.75,7.423828125 13.75,17.736328125 13.1494140625,19.7041015625 11.34765625,20.333984375 8.7890625,20.314453125 8.4765625,18.634765625 10.9375,18.791015625 11.904296875,18.478515625 12.2265625,17.462890625 12.2265625,7.423828125z M9.8828125,1.38867175579071L11.38671875,1.95507824420929 10.283203125,4.513671875 19.35546875,4.513671875 19.35546875,6.134765625 17.9296875,9.572265625 16.5234375,9.044921875 17.7734375,5.998046875 9.560546875,5.998046875 7.578125,9.357421875 6.3671875,8.361328125 8.369140625,5.01660108566284 9.8828125,1.38867175579071z M4.98046875,1.33007800579071L6.58203125,1.79882800579071 4.7265625,6.37890625 4.7265625,20.548828125 3.203125,20.548828125 3.203125,9.328125 0.91796863079071,12.755859375 0.25390625,11.037109375 2.998046875,6.4814453125 4.98046875,1.33007800579071z M23.916015625,6.955078125L23.26904296875,10.1630859375 22.71484375,12.326171875 24.78515625,13.95703125 25.83984375,10.84423828125 26.3671875,6.955078125 23.916015625,6.955078125z M28.5546875,2.716796875L38.92578125,2.716796875 38.92578125,4.259765625 34.765625,7.794921875 34.765625,10.158203125 39.7265625,10.158203125 39.7265625,11.583984375 34.765625,11.583984375 34.765625,17.833984375 34.1357421875,19.62109375 32.24609375,20.216796875 31.1962890625,20.20703125 29.6875,20.177734375 29.43359375,18.595703125 30.9619140625,18.7177734375 32.03125,18.771484375 32.9248046875,18.4833984375 33.22265625,17.619140625 33.22265625,11.583984375 27.8515625,11.583984375 27.8515625,10.158203125 33.22265625,10.158203125 33.22265625,7.111328125 36.7578125,4.142578125 28.5546875,4.142578125 28.5546875,2.716796875z M23.26171875,1.36914074420929L24.84375,1.58398425579071 24.1796875,5.490234375 27.87109375,5.490234375 27.87109375,6.759765625 27.1728515625,11.45458984375 25.95703125,14.89453125 28.515625,16.994140625 27.36328125,18.224609375 25.166015625,16.22265625 23.46435546875,18.35400390625 21.2890625,20.314453125 20.390625,19.044921875 22.47314453125,17.25048828125 24.072265625,15.24609375 21.1328125,12.736328125 21.806640625,10.05078125 22.421875,6.955078125 20.3515625,6.955078125 20.3515625,5.490234375 22.666015625,5.490234375 23.26171875,1.36914074420929z";
    2009年9月1日 4:39

全部回复

  • Xaml:

    <Path x:Name="Path1" Data="{Binding ElementName=Path1, Path=Tag}" Fill="Red"/>

    ------------------------------

    C#:

    Path.Tag = "F1 M8.92578125,10.314453125L10.41015625,10.802734375 7.5,17.482421875 6.03515625,16.837890625 8.92578125,10.314453125z M16.77734375,10.236328125L18.2080078125,13.2001953125 19.765625,16.623046875 18.28125,17.306640625 15.41015625,10.841796875 16.77734375,10.236328125z M12.2265625,7.423828125L13.75,7.423828125 13.75,17.736328125 13.1494140625,19.7041015625 11.34765625,20.333984375 8.7890625,20.314453125 8.4765625,18.634765625 10.9375,18.791015625 11.904296875,18.478515625 12.2265625,17.462890625 12.2265625,7.423828125z M9.8828125,1.38867175579071L11.38671875,1.95507824420929 10.283203125,4.513671875 19.35546875,4.513671875 19.35546875,6.134765625 17.9296875,9.572265625 16.5234375,9.044921875 17.7734375,5.998046875 9.560546875,5.998046875 7.578125,9.357421875 6.3671875,8.361328125 8.369140625,5.01660108566284 9.8828125,1.38867175579071z M4.98046875,1.33007800579071L6.58203125,1.79882800579071 4.7265625,6.37890625 4.7265625,20.548828125 3.203125,20.548828125 3.203125,9.328125 0.91796863079071,12.755859375 0.25390625,11.037109375 2.998046875,6.4814453125 4.98046875,1.33007800579071z M23.916015625,6.955078125L23.26904296875,10.1630859375 22.71484375,12.326171875 24.78515625,13.95703125 25.83984375,10.84423828125 26.3671875,6.955078125 23.916015625,6.955078125z M28.5546875,2.716796875L38.92578125,2.716796875 38.92578125,4.259765625 34.765625,7.794921875 34.765625,10.158203125 39.7265625,10.158203125 39.7265625,11.583984375 34.765625,11.583984375 34.765625,17.833984375 34.1357421875,19.62109375 32.24609375,20.216796875 31.1962890625,20.20703125 29.6875,20.177734375 29.43359375,18.595703125 30.9619140625,18.7177734375 32.03125,18.771484375 32.9248046875,18.4833984375 33.22265625,17.619140625 33.22265625,11.583984375 27.8515625,11.583984375 27.8515625,10.158203125 33.22265625,10.158203125 33.22265625,7.111328125 36.7578125,4.142578125 28.5546875,4.142578125 28.5546875,2.716796875z M23.26171875,1.36914074420929L24.84375,1.58398425579071 24.1796875,5.490234375 27.87109375,5.490234375 27.87109375,6.759765625 27.1728515625,11.45458984375 25.95703125,14.89453125 28.515625,16.994140625 27.36328125,18.224609375 25.166015625,16.22265625 23.46435546875,18.35400390625 21.2890625,20.314453125 20.390625,19.044921875 22.47314453125,17.25048828125 24.072265625,15.24609375 21.1328125,12.736328125 21.806640625,10.05078125 22.421875,6.955078125 20.3515625,6.955078125 20.3515625,5.490234375 22.666015625,5.490234375 23.26171875,1.36914074420929z";
    2009年9月1日 4:39
  • 楼上的方法最简单,还有一种自己解析String转换成PathGeometry,不过没这个绑定方便:)


    如果您觉得对您有帮助,请在“是否有帮助”点“是”;如果你觉得回复很满意,请“标记为已解答”
    2009年9月3日 2:51
    版主