|
| 1 | +## 目录 |
| 2 | + |
| 3 | +- [目录](#目录) |
| 4 | +- [移动视口](#移动视口) |
| 5 | +- [缩放](#缩放) |
| 6 | +- [自定义外观](#自定义外观) |
| 7 | + |
| 8 | +`Minimap` 控件是一个自定义控件,旨在为 `NodifyEditor` 提供同步的缩略视图。 |
| 9 | +它继承自 `ItemsControl`,通过 `ItemsSource` 属性显示项目。每个项目都包装在 `MinimapItem` 容器中,需在 `ItemContainerStyle` 中设置: |
| 10 | + |
| 11 | + |
| 12 | +> [!TIP] |
| 13 | +> 若希望在小地图中实时移动节点,需要将 `NodifyEditor.EnableDraggingContainersOptimizations` 设置为 `false`。 |
| 14 | +
|
| 15 | +此外,该控件还会显示一个表示编辑器可见区域的视口矩形,需要设置 `ViewportLocation` 和 `ViewportSize` 属性。 |
| 16 | + |
| 17 | +```xml |
| 18 | +<nodify:Minimap |
| 19 | + ItemsSource="{Binding ItemsSource, ElementName=Editor}" |
| 20 | + ViewportLocation="{Binding ViewportLocation, ElementName=Editor}" |
| 21 | + ViewportSize="{Binding ViewportSize, ElementName=Editor}" |
| 22 | + Zoom="OnMinimapZoom"> |
| 23 | + <nodify:Minimap.ItemContainerStyle> |
| 24 | + <Style TargetType="nodify:MinimapItem"> |
| 25 | + <Setter Property="Location" Value="{Binding MyItemLocation}" /> |
| 26 | + </Style> |
| 27 | + </nodify:Minimap.ItemContainerStyle> |
| 28 | +</nodify:Minimap> |
| 29 | +``` |
| 30 | + |
| 31 | +```csharp |
| 32 | +private void OnMinimapZoom(object sender, ZoomEventArgs e) |
| 33 | +{ |
| 34 | + Editor.ZoomAtPosition(e.Zoom, e.Location); |
| 35 | +} |
| 36 | +``` |
| 37 | + |
| 38 | +> [!IMPORTANT] |
| 39 | +> `Width` 和 `Height` 应由父容器限制,或在 `Minimap` 上设置为常量值,以防止其根据内容大小改变。 |
| 40 | +
|
| 41 | +## 移动视口 |
| 42 | + |
| 43 | +按住鼠标点击并拖动即可移动视口(平移)。若将 `IsReadOnly` 属性设置为 `true`,则无法移动。 |
| 44 | + |
| 45 | +在平移过程中,`ViewportLocation` 会更新,因此需要进行双向绑定(默认即为双向绑定)。 |
| 46 | + |
| 47 | +平移手势可通过设置 `EditorGestures.Mappings.Minimap.DragViewport` 为所需手势进行配置。 |
| 48 | + |
| 49 | +## 缩放 |
| 50 | + |
| 51 | +滚动鼠标滚轮即可进行缩放。若将 `IsReadOnly` 属性设置为 `true` 或未处理 `Zoom` 事件,则无法缩放。 |
| 52 | + |
| 53 | + |
| 54 | +缩放时的修饰键可通过设置 `EditorGestures.Mappings.Minimap.ZoomModifierKey` 为所需值进行配置。 |
| 55 | + |
| 56 | +## 自定义外观 |
| 57 | + |
| 58 | +可使用 `ViewportStyle` 自定义视口矩形的样式,例如: |
| 59 | + |
| 60 | +```xml |
| 61 | +<Style x:Key="MyViewportStyle" TargetType="Rectangle"> |
| 62 | + <Setter Property="Fill" Value="Transparent"/> |
| 63 | + <Setter Property="Stroke" Value="White"/> |
| 64 | + <Setter Property="StrokeThickness" Value="3"/> |
| 65 | +</Style> |
| 66 | + |
| 67 | +<nodify:Minimap ViewportStyle="{StaticResource MyViewportStyle}" ... /> |
| 68 | +``` |
| 69 | + |
| 70 | +`MaxViewportOffset` 属性用于限制在 [移动视口](#移动视口) 时,视口可偏离项目的最大距离。 |
| 71 | + |
| 72 | +`ResizeToViewport` 属性用于改变小地图的缩放行为。 |
| 73 | +若设置为 `true`,则小地图会始终与项目一起缩放,以显示视口。 |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | +如果设置为 `false`,则小地图仅显示项目,视口可以超出项目范围。 |
| 78 | + |
| 79 | + |
0 commit comments