0

I have a grid with an Image as Background and in the grid a canvas that draws a grid pattern.

Now I want that the Image size is exactly the size of the canvas but the Image is cuttet but if I Change the window size, the Image gets bigger.(To see this you Need to zoom out)
I just want an Image that is overlayed with this canvas. How can I do that? (the Image is 1920x1200)

My Code:

<Window x:Class="WpfTestApp.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Zoom="clr-namespace:PanAndZoom"
    xmlns:local="clr-namespace:WpfTestApp"
    mc:Ignorable="d"
    Title="MainWindow">
<DockPanel>
    <DockPanel DockPanel.Dock="Right" Background="#2F2F2F" Width="350">

    </DockPanel>
    <Zoom:ZoomBorder x:Name="border" ClipToBounds="True" Background="Gray">
        <Grid>

            <Image Width="1920" Height="1200" Source="C:\Users\nico\source\repos\WpfTestApp\WpfTestApp\Capture.PNG" HorizontalAlignment="Left" VerticalAlignment="Top" Stretch="Uniform" />
            <Canvas Width="1920" Height="1200">
                <Canvas.Background>
                    <DrawingBrush TileMode="Tile" Viewport="0,0,40,40" 
                                 ViewportUnits="Absolute">
                    <DrawingBrush.Drawing>
                        <GeometryDrawing>
                            <GeometryDrawing.Geometry>
                                <RectangleGeometry Rect="0,0,200,200"/>
                            </GeometryDrawing.Geometry>
                            <GeometryDrawing.Pen>
                                <Pen Brush="Red" Thickness="1"/>
                            </GeometryDrawing.Pen>
                        </GeometryDrawing>
                    </DrawingBrush.Drawing>
                </DrawingBrush>
            </Canvas.Background>
        </Canvas>
        </Grid>
    </Zoom:ZoomBorder>
</DockPanel>

Here is a link to the Zoom element.

SomePerson
  • 581
  • 1
  • 6
  • 18

0 Answers0