Example #1
0
 // This is needed in Silverlight because of a Silverlight bug
 // that causes a Path with a PathGeometry that was created using
 // <Path ... Data="M0 0 L10 20 ..." />
 // to have ZERO Bounds after trying to access the PathGeometry.Figures property.
 //
 // In both WPF and Silverlight Paths constructed using the Path markup syntax
 // using the StreamGeometry mini-language are supposed to be "black boxes".
 // There is no way to walk the PathGeometry.Figures to determine its actual geometry.
 // One can only get the PathGeometry.Bounds.
 // We have to treat it as a rectangular shape.
 // Note: Silverlight does not support the PathFigureCollection mini-language.
 // (Example: <PathGeometry Figures="M0 0 L10 20 ..." />.)
 // WPF supports both the StreamGeometry mini-language and the PathFigureCollection mini-language.
 //
 // So if the programmer wants to use a Node containing Paths for which Links want to
 // connect at the edge of the Paths (when Spot.None, of course),
 // they have to construct a PathFigureCollection containing PathFigures.
 //
 // But in Silverlight there is a bug causing the PathGeometry to have zero Bounds
 // once our code tries to get the value of PathGeometry.Figures,
 // if the Path was defined in XAML.
 // This causes that Path to disappear, to the consternation of our customers.
 // Typically that happenened (before version 1.2.6f) when routing a link to a node
 // containing a Path defined in XAML, when the Spot was None and no surrounding
 // Panel with a Background hid the actual shape of the Path.
 //
 // Our work-around requires our code to construct each PathGeometry with an
 // explicitly created PathFigureCollection containing PathFigures.
 // Explicitly setting PathGeometry.Figures gives it a local value which
 // tells this predicate that it's OK to try to get the PathGeometry.Figures property.
 // If it hasn't been set, it won't have a local value, which means
 // (most likely) that it was created in XAML using Data="...".
 public static bool PathGeometryHasFigures(PathGeometry path) {
   object val = path.ReadLocalValue(PathGeometry.FiguresProperty);
   var pfc = val as PathFigureCollection;
   return pfc != null && pfc.Count > 0;
 }