I want to get all features in the current extent of my PageLayoutControl's ActiveView. I got it working for a MapControl as described here.
With my PageLayoutControl it seems that I don't get the correct extent. When I fill the found features it looks like this:

Here is how I get the features:
Dictionary<String, IFeatureCursor> featureCursors = new Dictionary<String, IFeatureCursor>();
IMap map = this._pageLayoutControl.ActiveView.FocusMap;
// Get ActiveView from MapFrame
IActiveView tmpActiveView = null;
IGraphicsContainer graphicsContainer = (IGraphicsContainer)_pageLayoutControl.PageLayout;
graphicsContainer.Reset();
IElement element = graphicsContainer.Next();
while (element != null)
{
if (element is IMapFrame)
{
IMapFrame mapFrame = (IMapFrame)element;
tmpActiveView = (IActiveView)mapFrame.Map;
break;
}
element = graphicsContainer.Next();
}
if (tmpActiveView == null)
return featureCursors;
IEnvelope envelope = this._pageLayoutControl.ActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds; // FittedBounds;
// PageLayout has no SpatialReference. So use the View of the MapFrame
IPoint pointMax = tmpActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint((System.Int32)envelope.XMax, (System.Int32)envelope.YMax);
IPoint pointMin = tmpActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint((System.Int32)envelope.XMin, (System.Int32)envelope.YMin);
envelope.XMax = pointMax.X;
envelope.YMax = pointMax.Y;
envelope.XMin = pointMin.X;
envelope.YMin = pointMin.Y;
// Get Features in all layers
for (int iFeatLayer = 0; iFeatLayer < _pageLayoutControl.ActiveView.FocusMap.LayerCount; iFeatLayer++)
{
ILayer thisLayer = _pageLayoutControl.ActiveView.FocusMap.Layer[iFeatLayer];
IGeoFeatureLayer featLayer = thisLayer as IGeoFeatureLayer;
if (featLayer != null)
{
IFeatureClass featureClass = featLayer.FeatureClass;
System.String shapeFieldName = featureClass.ShapeFieldName;
// Create a new spatial filter and use the new envelope as the geometry
ISpatialFilter spatialFilter = new SpatialFilterClass();
spatialFilter.Geometry = envelope;
spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelEnvelopeIntersects;
spatialFilter.set_OutputSpatialReference(shapeFieldName, map.SpatialReference);
spatialFilter.GeometryField = shapeFieldName;
// Do the search
IFeatureCursor featureCursor = featureClass.Search(spatialFilter, false);
featureCursors.Add(thisLayer.Name, featureCursor);
}
}
return featureCursors;
What did I miss? :)