|
| 1 | +<UserControl xmlns="https://github.com/avaloniaui" |
| 2 | + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
| 3 | + xmlns:paz="using:Avalonia.Controls.PanAndZoom" |
| 4 | + x:Class="AvaloniaDemo.Views.CommandsView"> |
| 5 | + |
| 6 | + <Grid ColumnDefinitions="280,*"> |
| 7 | + <!-- Controls --> |
| 8 | + <ScrollViewer Grid.Column="0" VerticalScrollBarVisibility="Auto"> |
| 9 | + <StackPanel Margin="12" Spacing="8"> |
| 10 | + <TextBlock Text="Commands Demo" FontWeight="Bold" FontSize="16" /> |
| 11 | + <TextBlock Text="Demonstrates all ZoomBorder commands with MVVM binding" TextWrapping="Wrap" /> |
| 12 | + |
| 13 | + <Separator Margin="0,8" /> |
| 14 | + |
| 15 | + <TextBlock Text="Zoom Commands:" FontWeight="SemiBold" /> |
| 16 | + <StackPanel Orientation="Horizontal" Spacing="4"> |
| 17 | + <Button Content="Zoom In" |
| 18 | + Command="{Binding #ZoomBorder.ZoomInCommand}" |
| 19 | + Width="100" /> |
| 20 | + <Button Content="Zoom Out" |
| 21 | + Command="{Binding #ZoomBorder.ZoomOutCommand}" |
| 22 | + Width="100" /> |
| 23 | + </StackPanel> |
| 24 | + |
| 25 | + <Separator Margin="0,8" /> |
| 26 | + |
| 27 | + <TextBlock Text="View Commands:" FontWeight="SemiBold" /> |
| 28 | + <Button Content="Reset View" |
| 29 | + Command="{Binding #ZoomBorder.ResetCommand}" /> |
| 30 | + <Button Content="Fit to View" |
| 31 | + Command="{Binding #ZoomBorder.FitCommand}" /> |
| 32 | + <Button Content="Fill View" |
| 33 | + Command="{Binding #ZoomBorder.FillCommand}" /> |
| 34 | + |
| 35 | + <Separator Margin="0,8" /> |
| 36 | + |
| 37 | + <TextBlock Text="Stretch Commands:" FontWeight="SemiBold" /> |
| 38 | + <Button Content="Uniform Stretch" |
| 39 | + Command="{Binding #ZoomBorder.UniformCommand}" /> |
| 40 | + <Button Content="Uniform To Fill" |
| 41 | + Command="{Binding #ZoomBorder.UniformToFillCommand}" /> |
| 42 | + <Button Content="Toggle Stretch Mode" |
| 43 | + Command="{Binding #ZoomBorder.ToggleStretchCommand}" /> |
| 44 | + |
| 45 | + <Separator Margin="0,8" /> |
| 46 | + |
| 47 | + <TextBlock Text="Navigation Commands:" FontWeight="SemiBold" /> |
| 48 | + <StackPanel Orientation="Horizontal" Spacing="4"> |
| 49 | + <Button Content="← Back" |
| 50 | + Command="{Binding #ZoomBorder.NavigateBackCommand}" |
| 51 | + Width="100" /> |
| 52 | + <Button Content="Forward →" |
| 53 | + Command="{Binding #ZoomBorder.NavigateForwardCommand}" |
| 54 | + Width="100" /> |
| 55 | + </StackPanel> |
| 56 | + |
| 57 | + <Separator Margin="0,8" /> |
| 58 | + |
| 59 | + <TextBlock Text="Current State:" FontWeight="SemiBold" /> |
| 60 | + <StackPanel x:DataType="paz:ZoomBorder" DataContext="{Binding #ZoomBorder}" Spacing="4"> |
| 61 | + <TextBlock> |
| 62 | + <Run Text="Zoom X: " /> |
| 63 | + <Run Text="{Binding ZoomX, StringFormat=F3}" FontWeight="SemiBold" /> |
| 64 | + </TextBlock> |
| 65 | + <TextBlock> |
| 66 | + <Run Text="Zoom Y: " /> |
| 67 | + <Run Text="{Binding ZoomY, StringFormat=F3}" FontWeight="SemiBold" /> |
| 68 | + </TextBlock> |
| 69 | + <TextBlock> |
| 70 | + <Run Text="Offset X: " /> |
| 71 | + <Run Text="{Binding OffsetX, StringFormat=F1}" FontWeight="SemiBold" /> |
| 72 | + </TextBlock> |
| 73 | + <TextBlock> |
| 74 | + <Run Text="Offset Y: " /> |
| 75 | + <Run Text="{Binding OffsetY, StringFormat=F1}" FontWeight="SemiBold" /> |
| 76 | + </TextBlock> |
| 77 | + <TextBlock> |
| 78 | + <Run Text="Stretch: " /> |
| 79 | + <Run Text="{Binding Stretch}" FontWeight="SemiBold" /> |
| 80 | + </TextBlock> |
| 81 | + </StackPanel> |
| 82 | + |
| 83 | + <Separator Margin="0,8" /> |
| 84 | + |
| 85 | + <TextBlock Text="Settings:" FontWeight="SemiBold" /> |
| 86 | + <StackPanel x:DataType="paz:ZoomBorder" DataContext="{Binding #ZoomBorder}" Spacing="4"> |
| 87 | + <CheckBox Content="Enable Pan" IsChecked="{Binding EnablePan}" /> |
| 88 | + <CheckBox Content="Enable Zoom" IsChecked="{Binding EnableZoom}" /> |
| 89 | + <CheckBox Content="Enable View History" IsChecked="{Binding EnableViewHistory}" /> |
| 90 | + <CheckBox Content="Enable Animations" IsChecked="{Binding EnableAnimations}" /> |
| 91 | + </StackPanel> |
| 92 | + |
| 93 | + <Separator Margin="0,8" /> |
| 94 | + |
| 95 | + <TextBlock Text="Instructions:" FontWeight="SemiBold" /> |
| 96 | + <TextBlock TextWrapping="Wrap" FontSize="11"> |
| 97 | + All buttons above are bound to ZoomBorder commands using MVVM pattern: |
| 98 | + Command="{Binding #ZoomBorder.CommandName}". |
| 99 | + The buttons will be automatically enabled/disabled based on the command's CanExecute state. |
| 100 | + </TextBlock> |
| 101 | + <TextBlock TextWrapping="Wrap" FontSize="11" Margin="0,4,0,0"> |
| 102 | + Try the navigation commands - they require view history to be enabled and will only work after you've made some zoom/pan changes. |
| 103 | + </TextBlock> |
| 104 | + </StackPanel> |
| 105 | + </ScrollViewer> |
| 106 | + |
| 107 | + <!-- ZoomBorder --> |
| 108 | + <Border Grid.Column="1" Margin="12" BorderBrush="Gray" BorderThickness="1"> |
| 109 | + <paz:ZoomBorder x:Name="ZoomBorder" |
| 110 | + Stretch="None" |
| 111 | + ZoomSpeed="1.2" |
| 112 | + Background="SlateBlue" |
| 113 | + ClipToBounds="True" |
| 114 | + Focusable="True" |
| 115 | + EnableViewHistory="True" |
| 116 | + EnableAnimations="True"> |
| 117 | + <Canvas Width="600" Height="400" Background="LightGray"> |
| 118 | + <TextBlock Canvas.Left="20" Canvas.Top="20" |
| 119 | + Text="ZoomBorder Commands Demo" |
| 120 | + FontSize="24" FontWeight="Bold" /> |
| 121 | + |
| 122 | + <TextBlock Canvas.Left="20" Canvas.Top="60" |
| 123 | + Text="Use the command buttons on the left to control this view" |
| 124 | + FontSize="14" /> |
| 125 | + |
| 126 | + <!-- Sample content to zoom/pan --> |
| 127 | + <Rectangle Canvas.Left="50" Canvas.Top="120" |
| 128 | + Width="100" Height="100" |
| 129 | + Fill="Red" /> |
| 130 | + <TextBlock Canvas.Left="70" Canvas.Top="230" Text="Red" /> |
| 131 | + |
| 132 | + <Rectangle Canvas.Left="180" Canvas.Top="120" |
| 133 | + Width="100" Height="100" |
| 134 | + Fill="Green" /> |
| 135 | + <TextBlock Canvas.Left="195" Canvas.Top="230" Text="Green" /> |
| 136 | + |
| 137 | + <Rectangle Canvas.Left="310" Canvas.Top="120" |
| 138 | + Width="100" Height="100" |
| 139 | + Fill="Blue" /> |
| 140 | + <TextBlock Canvas.Left="330" Canvas.Top="230" Text="Blue" /> |
| 141 | + |
| 142 | + <Rectangle Canvas.Left="440" Canvas.Top="120" |
| 143 | + Width="100" Height="100" |
| 144 | + Fill="Orange" /> |
| 145 | + <TextBlock Canvas.Left="455" Canvas.Top="230" Text="Orange" /> |
| 146 | + |
| 147 | + <!-- Additional shapes --> |
| 148 | + <Ellipse Canvas.Left="50" Canvas.Top="280" |
| 149 | + Width="80" Height="80" |
| 150 | + Fill="Purple" /> |
| 151 | + <Ellipse Canvas.Left="170" Canvas.Top="280" |
| 152 | + Width="80" Height="80" |
| 153 | + Fill="Cyan" /> |
| 154 | + <Ellipse Canvas.Left="290" Canvas.Top="280" |
| 155 | + Width="80" Height="80" |
| 156 | + Fill="Magenta" /> |
| 157 | + <Ellipse Canvas.Left="410" Canvas.Top="280" |
| 158 | + Width="80" Height="80" |
| 159 | + Fill="Yellow" /> |
| 160 | + |
| 161 | + <Border Canvas.Left="510" Canvas.Top="280" |
| 162 | + Width="60" Height="80" |
| 163 | + Background="Black"> |
| 164 | + <TextBlock Text="Pan & Zoom!" |
| 165 | + Foreground="White" |
| 166 | + FontSize="10" |
| 167 | + TextWrapping="Wrap" |
| 168 | + TextAlignment="Center" |
| 169 | + VerticalAlignment="Center" /> |
| 170 | + </Border> |
| 171 | + </Canvas> |
| 172 | + </paz:ZoomBorder> |
| 173 | + </Border> |
| 174 | + </Grid> |
| 175 | + |
| 176 | +</UserControl> |
0 commit comments