harish rangaswamy
harish rangaswamy

Reputation: 51

wpf custom control scrolling

I have just started working on custom control in wpf. I have created an controlling inheriting from the Frameworkelement and I am drawing the content. The content is is bigger than the height of the window. The scroll is not appearing even after placing the control in the scrollviewer.

Upvotes: 1

Views: 581

Answers (2)

Jawahar
Jawahar

Reputation: 4885

Since you inherited from Framework Element and drawing your content using DrawingContext, the control may not measured properly. You should understand the Layout System of WPF. WPF followed two pass layout system. Measure and Arrange. In Measure Override, you need to tell the control how much size that need. In Arrange you need to place the control in proper rect.

The following case returns 300x300 pixels to the control. You may need to calculate the size based on your logic of rendering the content

    protected override Size MeasureOverride(Size availableSize)
    {
        return new Size(300, 300);
    }

Upvotes: 2

kidshaw
kidshaw

Reputation: 3451

Set:

ScrollViewer.VerticalScrollBarVisibility="Visible"

On your custom control. Also:

ScrollViewer.CanContentScroll="True"

Upvotes: 1

Related Questions