Skip to content

Instantly share code, notes, and snippets.

@josheinstein
Created July 13, 2012 16:33
Show Gist options
  • Save josheinstein/3105829 to your computer and use it in GitHub Desktop.
Save josheinstein/3105829 to your computer and use it in GitHub Desktop.
Disable DevExpress MapControl animation using reflection
/// <summary>
/// Uses reflection to disable the UseSprings dependency property which is read-only on map layers.
/// This will stop animations from occurring when the center point or zoom level of the map is changed.
/// </summary>
/// <param name="map">The map control to disable the animations for.</param>
/// <remarks>
/// Note that this method disables the UseSprings property in the layers currently added to the map. If
/// new layers are added, this method will need to be called again.
/// </remarks>
public static void DisableAnimation( this MapControl map )
{
try {
Type layerBaseType = typeof( DevExpress.Xpf.Map.LayerBase );
FieldInfo useSpringsField = layerBaseType.GetField( "UseSpringsPropertyKey", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public );
if ( useSpringsField != null ) {
var useSpringsPropertyKey = (System.Windows.DependencyPropertyKey)useSpringsField.GetValue( null );
foreach ( var layer in map.Layers ) {
layer.SetValue( useSpringsPropertyKey, false );
}
}
}
catch ( Exception error ) {
throw new InvalidOperationException( "Error disabling map animations. Reflection is fragile.", error );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment