能够在其父级为Grid的Canvas上绘制2D网格,但是当Grid的scrollViewer缩小时,该2D网格不会完全填充Grid(或Canvas,不确定是哪个。)
使用“ wpfhow如何在画布上绘制网格”一文中给出的解决方案
<UserControl x:Name="boardViewControl" x:Class="FWPFControlLibrary.BoardView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:FWPFControlLibrary"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid Background="{DynamicResource {x:Static SystemColors.AppWorkspaceBrushKey}}">
<ScrollViewer x:Name="scrollViewer" Margin="0" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" PanningMode="Both" PreviewMouseWheel="scrollViewer_PreviewMouseWheel" ManipulationDelta="scrollViewer_ManipulationDelta">
<Canvas x:Name="boardView" Width="300" Height="300">
<Canvas.Background>
<DrawingBrush TileMode="Tile" Viewport="-10,-10,20,20" ViewportUnits="Absolute">
<DrawingBrush.Drawing>
<GeometryDrawing>
<GeometryDrawing.Geometry>
<RectangleGeometry Rect="0,0,100,100"/>
</GeometryDrawing.Geometry>
<GeometryDrawing.Pen>
<Pen Brush="Gray" Thickness="1"/>
</GeometryDrawing.Pen>
</GeometryDrawing>
</DrawingBrush.Drawing>
</DrawingBrush>
</Canvas.Background>
</Canvas>
</ScrollViewer>
<Slider x:Name="zoomSlider" HorizontalAlignment="Right" VerticalAlignment="Bottom" Minimum="0.10" Maximum="3" SmallChange="0.10" TickFrequency="0.25" TickPlacement="TopLeft" Value="1" Foreground="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}" Orientation="Vertical" Height="100" Margin="0,0,25,25" LargeChange="0.25" />
</Grid>
</UserControl>
缩小时,右侧和底部的区域为空白。我期望2D网格完全填充可用区域,但事实并非如此。是否需要在此代码中添加一些绑定?