Thanks Andrew. However, there are a few cases in our app where we would like to toggle the visibility of an individual graphic within a GraphicsLayer and not the visiblity of the entire GraphicsLayer. Is there a way to do this?
for each gr as graphic in trycast(map.layers("MyGraphicsLayer"),graphicslayer) if gr.Attributes("NAME") = "TargetGraphic" Then if checkbox.isChecked = true then gr.symbol = CType(LayoutRoot.Resources("TransparentSymbol"),ESRI.ArcGIS.Client.Symbols.SimpleFillSymbol) else gr.symbol = CType(LayoutRoot.Resources("DefaultSymbol"),ESRI.ArcGIS.Client.Symbols.SimpleFillSymbol) end if end if next
I could be wrong but if a GraphicsLayer is using a Renderer, then an individual graphic's symbol property will be null (or maybe it has changed or even "fixed" if that wasn't ESRI's original intention) so the method you suggest may not always be applicable.
In any case, I found this on another post somewhere and it works great. Basically, setting the geometry to null hides the symbol. This also doesn't require any reflection; it's pure OO inheritance.
Public Class ExtendedGraphic Inherits ESRI.ArcGIS.Client.Graphic Private _storedGeometry As ESRI.ArcGIS.Client.Geometry.Geometry Public Property Visible() As Boolean Get Return Me.Geometry IsNot Nothing End Get Set(ByVal value As Boolean) If value <> Visible Then If value Then If _storedGeometry IsNot Nothing Then Me.Geometry = _storedGeometry Else If Me.Geometry IsNot Nothing Then _storedGeometry = Me.Geometry Me.Geometry = Nothing End If End If End Set End Property End Class
@Maxim: Note that changing internal properties through reflection can cause a lot of problems - You're really pulling the rug out under the SDK. Also not that these internals might not be available in future updates.
Type typeInQuestion = typeof(Graphic);
PropertyInfo field = typeInQuestion.GetProperty("Visibility", BindingFlags.NonPublic | BindingFlags.Instance);
field.SetValue(graphic, Visibility.Collapsed);
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.