views:

37

answers:

1

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.Data;
//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

+1  A: 

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.

AnthonyWJones
Thanks for the answer :) Although I need to create Path dynamically, so, i'll try to do that in code behind (c#).
Rahma
OK... I changed button by Path and MouseLeftButtonDown event, it works :)
Rahma