开发者

Cannot assign geometry to Button clip property

I'm working on an interactive map. I'm using Silverlight 4 within VisualStudio 2010. My problem is that I can't assign a geometry to Button Clip property:

Code:

bouton1.Clip = (PathGeometry)Forme.D开发者_如何学JAVAata;
//forme is a class that inherits from Path

when I run my application I get an ArgumentException:

The value is not included in the expected range


Your Path called "Forme" has its geometry defined using the Path Mini-Language right?

This type of Geometry cannot be share by multiple elements.

The work-around is store the path data as a string in a ResourceDictionary accessible to both your "Forme" element and "bouton1" then assign it using StaticResource. Something like:-

<StackPanel>
  <StackPanel.Resources>
    <sys:String x:Key="MyPath">M 10,100 C 10,300 300,-200 300,100</sys:String>
  </StackPanel.Resources>
  <Button x:Name="btn"  Content="Button" Height="150" Clip="{StaticResource MyPath}" />
  <Path Data="{StaticResource MyPath}" Stroke="Black" StrokeThickness="2"  />
</StackPanel>

The painful downside is that the VS2010 designer doesn't grasp this and therefore doesn't apply the path. You would need to run the app to visually see the results.


I changed button with Path and MouseLeftButtonDown event, it works :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜