Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Need help for proper control nesting of a scrollable image in a canvas

$
0
0

Trying to write an application that will use WPF to annotate a graphical image. Yes Im a newbie on WPF

I'm thinking the best container to do the drawing on is a canvas inside a scrollable window

I keep running into various issues

First I tried setting the image as the background of the canvas. The image was shrinking to the size of the canvas. So I figured I had to set the image as an element of the canvas, instead of its background

I want the image size to drive the size of the canvas, and scroll as needed

The only one I got halfway working was a scrollable window with a dockpanel inside

I was able to load the image into a dockpanel inside the scrollable window, and the image scrolled properly inside it

When I replaced the dockpanel with a canvas so I could add elements to it, the scroll bars went away. But I figure I half to use a canvas to draw the vector graphics on the drawing. Oh note the underlying drawing will never get changed - the graphics will be overlays on the drawing.

This is the xaml for what worked closest from a displaying the graphic scrolling correctly

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Ribbon x:Name="MainRibbon">
            <RibbonTab Header="Home" KeyTip="H" >
                <RibbonGroup x:Name="File">
                    <RibbonButton x:Name="FileOpenButton" Label="Open" LargeImageSource="Images\FileOpen.png" Click="FileOpenButton_Click" />
                </RibbonGroup>
                <RibbonGroup x:Name="Mark">
                    <RibbonButton x:Name="MarkDotTakeoff" Label="Mark" LargeImageSource="Images\MarkDot.png" Click="MarkDotTakeoff_Click"/>
                </RibbonGroup>
            </RibbonTab>
        </Ribbon>
        <ScrollViewer x:Name="DrawingScroll" Grid.Row="1" HorizontalScrollBarVisibility="Visible">
          <DockPanel Name="DrawingPanel">
            <Image x:Name="DrawingImage" Stretch="None"/>
          </DockPanel>
        </ScrollViewer>
    </Grid>

Drawing image was getting loaded by the click on the ribbon


Scott Berger McCormick Systems


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>