committed by
GitHub
5 changed files with 137 additions and 110 deletions
@ -1,66 +1,35 @@ |
|||
<UserControl xmlns="https://github.com/avaloniaui" |
|||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
|||
x:Class="ControlCatalog.Pages.ViewboxPage"> |
|||
<UserControl.Resources> |
|||
<StreamGeometry x:Key="Acorn"> |
|||
F1 M 16.6309,18.6563C 17.1309, |
|||
8.15625 29.8809,14.1563 29.8809, |
|||
14.1563C 30.8809,11.1563 34.1308, |
|||
11.4063 34.1308,11.4063C 33.5,12 |
|||
34.6309,13.1563 34.6309,13.1563C |
|||
32.1309,13.1562 31.1309,14.9062 |
|||
31.1309,14.9062C 41.1309,23.9062 |
|||
32.6309,27.9063 32.6309,27.9062C |
|||
24.6309,24.9063 21.1309,22.1562 |
|||
16.6309,18.6563 Z M 16.6309,19.9063C |
|||
21.6309,24.1563 25.1309,26.1562 |
|||
31.6309,28.6562C 31.6309,28.6562 |
|||
26.3809,39.1562 18.3809,36.1563C |
|||
18.3809,36.1563 18,38 16.3809,36.9063C |
|||
15,36 16.3809,34.9063 16.3809,34.9063C |
|||
16.3809,34.9063 10.1309,30.9062 16.6309,19.9063 Z |
|||
</StreamGeometry> |
|||
</UserControl.Resources> |
|||
|
|||
<Grid RowDefinitions="Auto,*"> |
|||
<Grid RowDefinitions="Auto,*,*"> |
|||
<StackPanel Orientation="Vertical" Spacing="4"> |
|||
<TextBlock Classes="h1">Viewbox</TextBlock> |
|||
<TextBlock Classes="h2">A control used to scale single child.</TextBlock> |
|||
</StackPanel> |
|||
<Grid ColumnDefinitions="Auto,*,*" |
|||
RowDefinitions="*,*,*,*" |
|||
Grid.Row="1" Margin="48" |
|||
MaxWidth="400"> |
|||
<TextBlock Grid.Row="0" VerticalAlignment="Center">None</TextBlock> |
|||
<TextBlock Grid.Row="1" VerticalAlignment="Center">Fill</TextBlock> |
|||
<TextBlock Grid.Row="2" VerticalAlignment="Center">Uniform</TextBlock> |
|||
<TextBlock Grid.Row="3" VerticalAlignment="Center">UniformToFill</TextBlock> |
|||
|
|||
<Viewbox Grid.Row="0" Grid.Column="1" Stretch="None"> |
|||
<TextBlock>Hello World!</TextBlock> |
|||
</Viewbox> |
|||
<Viewbox Grid.Row="1" Grid.Column="1" Stretch="Fill"> |
|||
<TextBlock>Hello World!</TextBlock> |
|||
</Viewbox> |
|||
<Viewbox Grid.Row="2" Grid.Column="1" Stretch="Uniform"> |
|||
<TextBlock>Hello World!</TextBlock> |
|||
</Viewbox> |
|||
<Viewbox Grid.Row="3" Grid.Column="1" Stretch="UniformToFill"> |
|||
<TextBlock>Hello World!</TextBlock> |
|||
</Viewbox> |
|||
<Grid Grid.Row="1" ColumnDefinitions="*,Auto" HorizontalAlignment="Center" Margin="0,10,0,0"> |
|||
|
|||
<Viewbox Grid.Row="0" Grid.Column="2" Stretch="None"> |
|||
<Path Fill="Blue" Data="{StaticResource Acorn}"/> |
|||
</Viewbox> |
|||
<Viewbox Grid.Row="1" Grid.Column="2" Stretch="Fill"> |
|||
<Path Fill="Blue" Data="{StaticResource Acorn}"/> |
|||
</Viewbox> |
|||
<Viewbox Grid.Row="2" Grid.Column="2" Stretch="Uniform"> |
|||
<Path Fill="Blue" Data="{StaticResource Acorn}"/> |
|||
</Viewbox> |
|||
<Viewbox Grid.Row="3" Grid.Column="2" Stretch="UniformToFill"> |
|||
<Path Fill="Blue" Data="{StaticResource Acorn}"/> |
|||
</Viewbox> |
|||
<Border HorizontalAlignment="Center" Grid.Column="0" BorderThickness="1" BorderBrush="Orange" Width="200" Height="200"> |
|||
<Border VerticalAlignment="Center" HorizontalAlignment="Center" Grid.Column="0" BorderThickness="1" BorderBrush="CornflowerBlue" Width="{Binding #WidthSlider.Value}" Height="{Binding #HeightSlider.Value}" > |
|||
<Viewbox x:Name="Viewbox" |
|||
StretchDirection="{Binding #StretchDirectionSelector.SelectedItem}"> |
|||
<Ellipse Width="50" Height="50" Fill="CornflowerBlue" /> |
|||
</Viewbox> |
|||
</Border> |
|||
</Border> |
|||
|
|||
<StackPanel HorizontalAlignment="Left" Orientation="Vertical" Grid.Column="1" Margin="8,0,0,0" Width="150"> |
|||
<TextBlock Text="Width" /> |
|||
<Slider Minimum="10" Maximum="200" Value="100" x:Name="WidthSlider" TickFrequency="25" TickPlacement="TopLeft" /> |
|||
<TextBlock Text="Height" /> |
|||
<Slider Minimum="10" Maximum="200" Value="100" x:Name="HeightSlider" TickFrequency="25" TickPlacement="TopLeft" /> |
|||
<TextBlock Text="Stretch" /> |
|||
<ComboBox x:Name="StretchSelector" HorizontalAlignment="Stretch" Margin="0,0,0,2" SelectionChanged="StretchSelector_OnSelectionChanged" /> |
|||
<TextBlock Text="Stretch Direction" /> |
|||
<ComboBox x:Name="StretchDirectionSelector" HorizontalAlignment="Stretch" /> |
|||
</StackPanel> |
|||
</Grid> |
|||
|
|||
</Grid> |
|||
</UserControl> |
|||
|
|||
@ -1,18 +1,47 @@ |
|||
using Avalonia.Controls; |
|||
using Avalonia.Markup.Xaml; |
|||
using Avalonia.Media; |
|||
|
|||
namespace ControlCatalog.Pages |
|||
{ |
|||
public class ViewboxPage : UserControl |
|||
{ |
|||
private readonly Viewbox _viewbox; |
|||
private readonly ComboBox _stretchSelector; |
|||
|
|||
public ViewboxPage() |
|||
{ |
|||
this.InitializeComponent(); |
|||
InitializeComponent(); |
|||
|
|||
_viewbox = this.FindControl<Viewbox>("Viewbox"); |
|||
|
|||
_stretchSelector = this.FindControl<ComboBox>("StretchSelector"); |
|||
|
|||
_stretchSelector.Items = new[] |
|||
{ |
|||
Stretch.Uniform, Stretch.UniformToFill, Stretch.Fill, Stretch.None |
|||
}; |
|||
|
|||
_stretchSelector.SelectedIndex = 0; |
|||
|
|||
var stretchDirectionSelector = this.FindControl<ComboBox>("StretchDirectionSelector"); |
|||
|
|||
stretchDirectionSelector.Items = new[] |
|||
{ |
|||
StretchDirection.Both, StretchDirection.DownOnly, StretchDirection.UpOnly |
|||
}; |
|||
|
|||
stretchDirectionSelector.SelectedIndex = 0; |
|||
} |
|||
|
|||
private void InitializeComponent() |
|||
{ |
|||
AvaloniaXamlLoader.Load(this); |
|||
} |
|||
|
|||
private void StretchSelector_OnSelectionChanged(object sender, SelectionChangedEventArgs e) |
|||
{ |
|||
_viewbox.Stretch = (Stretch) _stretchSelector.SelectedItem!; |
|||
} |
|||
} |
|||
} |
|||
|
|||
Loading…
Reference in new issue