none
如何让Path当做ListBox.Background的值 RRS feed

  • 问题

  •  <ListBox.Background>
                        
                                <Path Data=" M 166.979980,0.072754 C 177.454590,3.563965 187.428711,7.196777 197.354980,12.048828 C 186.879883,8.557129 177.160156,4.276855 166.979980,0.072754">
                                <Path.Fill>
                                    <LinearGradientBrush MappingMode="Absolute" StartPoint="206.919434,656.222168" EndPoint="195.395905,676.181519">
                                        <LinearGradientBrush.GradientStops>
                                            <GradientStop Offset="0.000000" Color="#ffff0000"/>
                                            <GradientStop Offset="0.490000" Color="#ffffff00"/>
                                            <GradientStop Offset="1.000000" Color="#ffff0000"/>
                                        </LinearGradientBrush.GradientStops>
                                        <LinearGradientBrush.Transform>
                                            <MatrixTransform Matrix="1.000000,0.000000,-0.000000,-1.000000,-18.876953,672.458496" />
                                        </LinearGradientBrush.Transform>
                                    </LinearGradientBrush>
                                </Path.Fill>
                            </Path>
                                      </ListBox.Background>

    提示说属性“Background”不支持类型“Path”的值,有什么方法让它支持么?

    2011年4月21日 2:41

答案

  • 问题在于你的代码明显类型不匹配,Background是Brush类型, Path是一个 Shapele类型,两者没有任何直接联系。

    解决方法是,你要把你的Path放入一个 VisualBrush 然后才可以设置到你的 Background上。

          <ListBox.Background>
            <VisualBrush>
              <VisualBrush.Visual>
                <Path Data=" M 166.979980,0.072754 C 177.454590,3.563965 187.428711,7.196777 197.354980,12.048828 C 186.879883,8.557129 177.160156,4.276855 166.979980,0.072754">
                  <Path.Fill>
                    <LinearGradientBrush MappingMode="Absolute" StartPoint="206.919434,656.222168" EndPoint="195.395905,676.181519">
                      <LinearGradientBrush.GradientStops>
                        <GradientStop Offset="0.000000" Color="#ffff0000"/>
                        <GradientStop Offset="0.490000" Color="#ffffff00"/>
                        <GradientStop Offset="1.000000" Color="#ffff0000"/>
                      </LinearGradientBrush.GradientStops>
                      <LinearGradientBrush.Transform>
                        <MatrixTransform Matrix="1.000000,0.000000,-0.000000,-1.000000,-18.876953,672.458496" />
                      </LinearGradientBrush.Transform>
                    </LinearGradientBrush>
                  </Path.Fill>
                </Path>
              </VisualBrush.Visual>
            </VisualBrush>
          </ListBox.Background>
    

    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • 已建议为答案 Jie BaoModerator 2011年4月21日 3:10
    • 已标记为答案 yooho 2011年4月22日 1:16
    2011年4月21日 3:10
    版主