c# - How to find the center of a expanding expander -
ok has me puzzled , should simple
i have code
private void expander_expanded(object sender, routedeventargs e) { var expand = e.originalsource expander; if (expand != null) { var layer = sender layerbase; var middle = expand.translatepoint(new point(), layer) + new vector(expand.actualwidth/2,expand.actualheight/2); location.centre = layer.screentogeopoint(middle); e.handled = true; } }
this code supposed do,
- locate screen point in centre of control
- locate geographic point relates screen point
- recentre map coordinates
this ensure expander in centre of displayed map, out moving expander relative map (ie top left corner still in correct geographic location)
the code functioning however, actualheight , actualwidth returning size of collapsed expander, throwing off centre point large margin, i'm assuming because expanded event firing before control redraws. how capture expanded has changed after visual tree redraws?
private async void expander_expanded(object sender, routedeventargs e) { var expand = e.originalsource expander; if (expand != null) { var layer = sender layerbase; // magic await dispatcher.invokeasync( ( ) => { } ); expand.updatelayout(); var middle = expand.translatepoint(new point(), layer) + new vector(expand.actualwidth/2,expand.actualheight/2); location.centre = layer.screentogeopoint(middle); e.handled = true; } }
this works :)
Comments
Post a Comment