committed by
GitHub
46 changed files with 1547 additions and 540 deletions
@ -0,0 +1,5 @@ |
|||||
|
<ProjectConfiguration> |
||||
|
<Settings> |
||||
|
<IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely> |
||||
|
</Settings> |
||||
|
</ProjectConfiguration> |
||||
@ -1,33 +1,41 @@ |
|||||
<UserControl xmlns="https://github.com/avaloniaui" |
<UserControl xmlns="https://github.com/avaloniaui" |
||||
xmlns:pages="clr-namespace:ControlCatalog.Pages" |
xmlns:pages="clr-namespace:ControlCatalog.Pages" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
<TabControl Classes="sidebar" Name="Sidebar"> |
Background="{DynamicResource ThemeBackgroundBrush}" |
||||
<TabControl.PageTransition> |
Foreground="{DynamicResource ThemeForegroundBrush}" |
||||
<CrossFade Duration="0.25"/> |
FontSize="{DynamicResource FontSizeNormal}"> |
||||
</TabControl.PageTransition> |
<Grid> |
||||
<TabItem Header="AutoCompleteBox"><pages:AutoCompleteBoxPage/></TabItem> |
<DropDown x:Name="Themes" SelectedIndex="0" Width="100" Margin="8" HorizontalAlignment="Right" VerticalAlignment="Bottom"> |
||||
<TabItem Header="Border"><pages:BorderPage/></TabItem> |
<DropDownItem>Light</DropDownItem> |
||||
<TabItem Header="Button"><pages:ButtonPage/></TabItem> |
<DropDownItem>Dark</DropDownItem> |
||||
<TabItem Header="ButtonSpinner"><pages:ButtonSpinnerPage/></TabItem> |
</DropDown> |
||||
<TabItem Header="Calendar"><pages:CalendarPage/></TabItem> |
<TabControl Classes="sidebar" Name="Sidebar"> |
||||
<TabItem Header="Canvas"><pages:CanvasPage/></TabItem> |
<TabItem Header="AutoCompleteBox"><pages:AutoCompleteBoxPage/></TabItem> |
||||
<TabItem Header="Carousel"><pages:CarouselPage/></TabItem> |
<TabItem Header="Border"><pages:BorderPage/></TabItem> |
||||
<TabItem Header="CheckBox"><pages:CheckBoxPage/></TabItem> |
<TabItem Header="Button"><pages:ButtonPage/></TabItem> |
||||
<TabItem Header="ContextMenu"><pages:ContextMenuPage/></TabItem> |
<TabItem Header="ButtonSpinner"><pages:ButtonSpinnerPage/></TabItem> |
||||
<TabItem Header="DatePicker"><pages:DatePickerPage/></TabItem> |
<TabItem Header="Calendar"><pages:CalendarPage/></TabItem> |
||||
<TabItem Header="Drag+Drop"><pages:DragAndDropPage/></TabItem> |
<TabItem Header="Canvas"><pages:CanvasPage/></TabItem> |
||||
<TabItem Header="DropDown"><pages:DropDownPage/></TabItem> |
<TabItem Header="Carousel"><pages:CarouselPage/></TabItem> |
||||
<TabItem Header="Expander"><pages:ExpanderPage/></TabItem> |
<TabItem Header="CheckBox"><pages:CheckBoxPage/></TabItem> |
||||
<TabItem Header="Image"><pages:ImagePage/></TabItem> |
<TabItem Header="ContextMenu"><pages:ContextMenuPage/></TabItem> |
||||
<TabItem Header="LayoutTransformControl"><pages:LayoutTransformControlPage/></TabItem> |
<TabItem Header="DatePicker"><pages:DatePickerPage/></TabItem> |
||||
<TabItem Header="ListBox"><pages:ListBoxPage/></TabItem> |
<TabItem Header="Drag+Drop"><pages:DragAndDropPage/></TabItem> |
||||
<TabItem Header="Menu"><pages:MenuPage/></TabItem> |
<TabItem Header="DropDown"><pages:DropDownPage/></TabItem> |
||||
<TabItem Header="NumericUpDown"><pages:NumericUpDownPage/></TabItem> |
<TabItem Header="Expander"><pages:ExpanderPage/></TabItem> |
||||
<TabItem Header="ProgressBar"><pages:ProgressBarPage/></TabItem> |
<TabItem Header="Image"><pages:ImagePage/></TabItem> |
||||
<TabItem Header="RadioButton"><pages:RadioButtonPage/></TabItem> |
<TabItem Header="LayoutTransformControl"><pages:LayoutTransformControlPage/></TabItem> |
||||
<TabItem Header="Slider"><pages:SliderPage/></TabItem> |
<TabItem Header="ListBox"><pages:ListBoxPage/></TabItem> |
||||
<TabItem Header="TextBox"><pages:TextBoxPage/></TabItem> |
<TabItem Header="Menu"><pages:MenuPage/></TabItem> |
||||
<TabItem Header="ToolTip"><pages:ToolTipPage/></TabItem> |
<TabItem Header="NumericUpDown"><pages:NumericUpDownPage/></TabItem> |
||||
<TabItem Header="TreeView"><pages:TreeViewPage/></TabItem> |
<TabItem Header="ProgressBar"><pages:ProgressBarPage/></TabItem> |
||||
</TabControl> |
<TabItem Header="RadioButton"><pages:RadioButtonPage/></TabItem> |
||||
|
<TabItem Header="Slider"><pages:SliderPage/></TabItem> |
||||
|
<TabItem Header="TextBox"><pages:TextBoxPage/></TabItem> |
||||
|
<TabItem Header="ToolTip"><pages:ToolTipPage/></TabItem> |
||||
|
<TabItem Header="TreeView"><pages:TreeViewPage/></TabItem> |
||||
|
<TabItem Header="TabControl"><pages:TabControlPage/></TabItem> |
||||
|
<TabItem Header="Viewbox"><pages:ViewboxPage/></TabItem> |
||||
|
</TabControl> |
||||
|
</Grid> |
||||
</UserControl> |
</UserControl> |
||||
|
|||||
@ -0,0 +1,97 @@ |
|||||
|
<UserControl xmlns="https://github.com/avaloniaui"> |
||||
|
<DockPanel> |
||||
|
<TextBlock |
||||
|
DockPanel.Dock="Top" |
||||
|
Classes="h1" |
||||
|
Text="TabControl" |
||||
|
Margin="4"> |
||||
|
</TextBlock> |
||||
|
<TextBlock |
||||
|
DockPanel.Dock="Top" |
||||
|
Classes="h2" |
||||
|
Text="A tab control that displays a tab strip along with the content of the selected tab" |
||||
|
Margin="4"> |
||||
|
</TextBlock> |
||||
|
<Grid |
||||
|
ColumnDefinitions="*,*" |
||||
|
RowDefinitions="*,100"> |
||||
|
<DockPanel |
||||
|
Grid.Column="0" |
||||
|
Margin="4"> |
||||
|
<TextBlock |
||||
|
DockPanel.Dock="Top" |
||||
|
Classes="h1" |
||||
|
Text="From Inline TabItems"> |
||||
|
</TextBlock> |
||||
|
<TabControl |
||||
|
Margin="0 16" |
||||
|
TabStripPlacement="{Binding TabPlacement}"> |
||||
|
<TabItem Header="Arch"> |
||||
|
<StackPanel Orientation="Vertical" Spacing="8"> |
||||
|
<TextBlock>This is the first page in the TabControl.</TextBlock> |
||||
|
<Image Source="resm:ControlCatalog.Assets.delicate-arch-896885_640.jpg" Width="300"/> |
||||
|
</StackPanel> |
||||
|
</TabItem> |
||||
|
<TabItem Header="Leaf"> |
||||
|
<StackPanel Orientation="Vertical" Spacing="8"> |
||||
|
<TextBlock>This is the second page in the TabControl.</TextBlock> |
||||
|
<Image Source="resm:ControlCatalog.Assets.maple-leaf-888807_640.jpg" Width="300"/> |
||||
|
</StackPanel> |
||||
|
</TabItem> |
||||
|
<TabItem Header="Disabled" IsEnabled="False"> |
||||
|
<TextBlock>You should not see this.</TextBlock> |
||||
|
</TabItem> |
||||
|
</TabControl> |
||||
|
</DockPanel> |
||||
|
<DockPanel |
||||
|
Grid.Column="1" |
||||
|
Margin="4"> |
||||
|
<TextBlock |
||||
|
DockPanel.Dock="Top" |
||||
|
Classes="h1" |
||||
|
Text="From DataTemplate"> |
||||
|
</TextBlock> |
||||
|
<TabControl |
||||
|
Items="{Binding Tabs}" |
||||
|
Margin="0 16" |
||||
|
TabStripPlacement="{Binding TabPlacement}"> |
||||
|
<TabControl.ItemTemplate> |
||||
|
<DataTemplate> |
||||
|
<TextBlock |
||||
|
Text="{Binding Header}"> |
||||
|
</TextBlock> |
||||
|
</DataTemplate> |
||||
|
</TabControl.ItemTemplate> |
||||
|
<TabControl.ContentTemplate> |
||||
|
<DataTemplate> |
||||
|
<StackPanel Orientation="Vertical" Spacing="8"> |
||||
|
<TextBlock Text="{Binding Text}"/> |
||||
|
<Image Source="{Binding Image}" Width="300"/> |
||||
|
</StackPanel> |
||||
|
</DataTemplate> |
||||
|
</TabControl.ContentTemplate> |
||||
|
<TabControl.Styles> |
||||
|
<Style Selector="TabItem"> |
||||
|
<Setter Property="IsEnabled" Value="{Binding IsEnabled}"/> |
||||
|
</Style> |
||||
|
</TabControl.Styles> |
||||
|
</TabControl> |
||||
|
</DockPanel> |
||||
|
<StackPanel |
||||
|
Grid.Row="1" |
||||
|
Grid.ColumnSpan="2" |
||||
|
Orientation="Horizontal" |
||||
|
Spacing="8" |
||||
|
HorizontalAlignment="Center" |
||||
|
VerticalAlignment="Center"> |
||||
|
<TextBlock VerticalAlignment="Center">Tab Placement:</TextBlock> |
||||
|
<DropDown SelectedIndex="{Binding TabPlacement, Mode=TwoWay}"> |
||||
|
<DropDownItem>Left</DropDownItem> |
||||
|
<DropDownItem>Bottom</DropDownItem> |
||||
|
<DropDownItem>Right</DropDownItem> |
||||
|
<DropDownItem>Top</DropDownItem> |
||||
|
</DropDown> |
||||
|
</StackPanel> |
||||
|
</Grid> |
||||
|
</DockPanel> |
||||
|
</UserControl> |
||||
@ -0,0 +1,80 @@ |
|||||
|
using System; |
||||
|
|
||||
|
using Avalonia; |
||||
|
using Avalonia.Controls; |
||||
|
using Avalonia.Markup.Xaml; |
||||
|
using Avalonia.Media.Imaging; |
||||
|
using Avalonia.Platform; |
||||
|
|
||||
|
using ReactiveUI; |
||||
|
|
||||
|
namespace ControlCatalog.Pages |
||||
|
{ |
||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
public class TabControlPage : UserControl |
||||
|
{ |
||||
|
public TabControlPage() |
||||
|
{ |
||||
|
InitializeComponent(); |
||||
|
|
||||
|
DataContext = new PageViewModel |
||||
|
{ |
||||
|
Tabs = new[] |
||||
|
{ |
||||
|
new TabItemViewModel |
||||
|
{ |
||||
|
Header = "Arch", |
||||
|
Text = "This is the first templated tab page.", |
||||
|
Image = LoadBitmap("resm:ControlCatalog.Assets.delicate-arch-896885_640.jpg?assembly=ControlCatalog"), |
||||
|
}, |
||||
|
new TabItemViewModel |
||||
|
{ |
||||
|
Header = "Leaf", |
||||
|
Text = "This is the second templated tab page.", |
||||
|
Image = LoadBitmap("resm:ControlCatalog.Assets.maple-leaf-888807_640.jpg?assembly=ControlCatalog"), |
||||
|
}, |
||||
|
new TabItemViewModel |
||||
|
{ |
||||
|
Header = "Disabled", |
||||
|
Text = "You should not see this.", |
||||
|
IsEnabled = false, |
||||
|
}, |
||||
|
}, |
||||
|
TabPlacement = Dock.Top, |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
private void InitializeComponent() |
||||
|
{ |
||||
|
AvaloniaXamlLoader.Load(this); |
||||
|
} |
||||
|
|
||||
|
private IBitmap LoadBitmap(string uri) |
||||
|
{ |
||||
|
var assets = AvaloniaLocator.Current.GetService<IAssetLoader>(); |
||||
|
return new Bitmap(assets.Open(new Uri(uri))); |
||||
|
} |
||||
|
|
||||
|
private class PageViewModel : ReactiveObject |
||||
|
{ |
||||
|
private Dock _tabPlacement; |
||||
|
|
||||
|
public TabItemViewModel[] Tabs { get; set; } |
||||
|
|
||||
|
public Dock TabPlacement |
||||
|
{ |
||||
|
get { return _tabPlacement; } |
||||
|
set { this.RaiseAndSetIfChanged(ref _tabPlacement, value); } |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private class TabItemViewModel |
||||
|
{ |
||||
|
public string Header { get; set; } |
||||
|
public string Text { get; set; } |
||||
|
public IBitmap Image { get; set; } |
||||
|
public bool IsEnabled { get; set; } = true; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,65 @@ |
|||||
|
<UserControl xmlns="https://github.com/avaloniaui" |
||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> |
||||
|
<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,*"> |
||||
|
<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> |
||||
|
|
||||
|
<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> |
||||
|
</Grid> |
||||
|
</Grid> |
||||
|
</UserControl> |
||||
@ -0,0 +1,18 @@ |
|||||
|
using Avalonia.Controls; |
||||
|
using Avalonia.Markup.Xaml; |
||||
|
|
||||
|
namespace ControlCatalog.Pages |
||||
|
{ |
||||
|
public class ViewboxPage : UserControl |
||||
|
{ |
||||
|
public ViewboxPage() |
||||
|
{ |
||||
|
this.InitializeComponent(); |
||||
|
} |
||||
|
|
||||
|
private void InitializeComponent() |
||||
|
{ |
||||
|
AvaloniaXamlLoader.Load(this); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,52 +1,66 @@ |
|||||
<Styles xmlns="https://github.com/avaloniaui" |
<Styles xmlns="https://github.com/avaloniaui" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" > |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" > |
||||
<Style Selector="TabControl.sidebar"> |
<Style Selector="TabControl.sidebar"> |
||||
<Setter Property="Template"> |
<Setter Property="TabStripPlacement" Value="Left"/> |
||||
<ControlTemplate> |
<Setter Property="Padding" Value="8 0 0 0"/> |
||||
<DockPanel> |
<Setter Property="Background" Value="{DynamicResource ThemeAccentBrush}"/> |
||||
<ScrollViewer MinWidth="190" Background="{DynamicResource ThemeAccentBrush}" DockPanel.Dock="Left"> |
<Setter Property="Template"> |
||||
<TabStrip Name="PART_TabStrip" |
<ControlTemplate> |
||||
MemberSelector="{x:Static TabControl.HeaderSelector}" |
<Border |
||||
Items="{TemplateBinding Items}" |
Margin="{TemplateBinding Margin}" |
||||
SelectedIndex="{TemplateBinding SelectedIndex, Mode=TwoWay}"> |
BorderBrush="{TemplateBinding BorderBrush}" |
||||
<TabStrip.ItemsPanel> |
BorderThickness="{TemplateBinding BorderThickness}"> |
||||
<ItemsPanelTemplate> |
<DockPanel> |
||||
<StackPanel Orientation="Vertical"/> |
<ScrollViewer |
||||
</ItemsPanelTemplate> |
Name="PART_ScrollViewer" |
||||
</TabStrip.ItemsPanel> |
HorizontalScrollBarVisibility="{TemplateBinding (ScrollViewer.HorizontalScrollBarVisibility)}" |
||||
</TabStrip> |
VerticalScrollBarVisibility="{TemplateBinding (ScrollViewer.VerticalScrollBarVisibility)}" |
||||
</ScrollViewer> |
Background="{TemplateBinding Background}"> |
||||
<Carousel Name="PART_Content" |
<ItemsPresenter |
||||
Margin="8 0 0 0" |
Name="PART_ItemsPresenter" |
||||
MemberSelector="{x:Static TabControl.ContentSelector}" |
Items="{TemplateBinding Items}" |
||||
Items="{TemplateBinding Items}" |
ItemsPanel="{TemplateBinding ItemsPanel}" |
||||
SelectedIndex="{TemplateBinding SelectedIndex}" |
ItemTemplate="{TemplateBinding ItemTemplate}" |
||||
PageTransition="{TemplateBinding PageTransition}" |
MemberSelector="{TemplateBinding MemberSelector}"> |
||||
Grid.Row="1"/> |
</ItemsPresenter> |
||||
</DockPanel> |
</ScrollViewer> |
||||
</ControlTemplate> |
<ContentPresenter |
||||
</Setter> |
Name="PART_Content" |
||||
</Style> |
Margin="{TemplateBinding Padding}" |
||||
|
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" |
||||
|
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" |
||||
|
Content="{TemplateBinding SelectedContent}" |
||||
|
ContentTemplate="{TemplateBinding SelectedContentTemplate}"> |
||||
|
</ContentPresenter> |
||||
|
</DockPanel> |
||||
|
</Border> |
||||
|
</ControlTemplate> |
||||
|
</Setter> |
||||
|
</Style> |
||||
|
|
||||
<Style Selector="TabControl.sidebar TabStripItem"> |
<Style Selector="TabControl.sidebar > TabItem"> |
||||
<Setter Property="Foreground" Value="White"/> |
<Setter Property="BorderThickness" Value="0"/> |
||||
<Setter Property="FontSize" Value="14"/> |
<Setter Property="Foreground" Value="White"/> |
||||
<Setter Property="Margin" Value="0"/> |
<Setter Property="FontSize" Value="14"/> |
||||
<Setter Property="Padding" Value="16"/> |
<Setter Property="Margin" Value="0"/> |
||||
<Setter Property="Opacity" Value="0.5"/> |
<Setter Property="Padding" Value="16"/> |
||||
<Setter Property="Transitions"> |
<Setter Property="Opacity" Value="0.5"/> |
||||
<Transitions> |
<Setter Property="Transitions"> |
||||
<DoubleTransition Property="Opacity" Duration="0:0:0.2"/> |
<Transitions> |
||||
</Transitions> |
<DoubleTransition Property="Opacity" Duration="0:0:0.5"/> |
||||
</Setter> |
</Transitions> |
||||
</Style> |
</Setter> |
||||
|
</Style> |
||||
<Style Selector="TabControl.sidebar TabStripItem:pointerover"> |
<Style Selector="TabControl.sidebar > TabItem:pointerover"> |
||||
<Setter Property="Opacity" Value="1"/> |
<Setter Property="Opacity" Value="1"/> |
||||
</Style> |
</Style> |
||||
|
<Style Selector="TabControl.sidebar > TabItem:pointerover /template/ ContentPresenter#PART_ContentPresenter"> |
||||
<Style Selector="TabControl.sidebar TabStripItem:selected"> |
<Setter Property="Background" Value="Transparent"/> |
||||
<Setter Property="Background" Value="{DynamicResource ThemeAccentBrush2}"/> |
</Style> |
||||
<Setter Property="Opacity" Value="1"/> |
<Style Selector="TabControl.sidebar > TabItem:selected"> |
||||
</Style> |
<Setter Property="Opacity" Value="1"/> |
||||
|
</Style> |
||||
|
<Style Selector="TabControl.sidebar > TabItem:selected /template/ ContentPresenter#PART_ContentPresenter"> |
||||
|
<Setter Property="Background" Value="{DynamicResource ThemeAccentBrush2}"/> |
||||
|
</Style> |
||||
</Styles> |
</Styles> |
||||
|
|||||
@ -1,53 +1,66 @@ |
|||||
<Styles xmlns="https://github.com/avaloniaui" |
<Styles xmlns="https://github.com/avaloniaui" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" > |
||||
xmlns:a="clr-namespace:Avalonia.Media.Animations;assembly=Avalonia.Media.Animations"> |
<Style Selector="TabControl.sidebar"> |
||||
<Style Selector="TabControl.sidebar"> |
<Setter Property="TabStripPlacement" Value="Left"/> |
||||
<Setter Property="Template"> |
<Setter Property="Padding" Value="8 0 0 0"/> |
||||
<ControlTemplate> |
<Setter Property="Background" Value="{DynamicResource ThemeAccentBrush}"/> |
||||
<DockPanel> |
<Setter Property="Template"> |
||||
<ScrollViewer MinWidth="190" Background="{DynamicResource ThemeAccentBrush}" DockPanel.Dock="Left"> |
<ControlTemplate> |
||||
<TabStrip Name="PART_TabStrip" |
<Border |
||||
MemberSelector="{x:Static TabControl.HeaderSelector}" |
Margin="{TemplateBinding Margin}" |
||||
Items="{TemplateBinding Items}" |
BorderBrush="{TemplateBinding BorderBrush}" |
||||
SelectedIndex="{TemplateBinding SelectedIndex, Mode=TwoWay}"> |
BorderThickness="{TemplateBinding BorderThickness}"> |
||||
<TabStrip.ItemsPanel> |
<DockPanel> |
||||
<ItemsPanelTemplate> |
<ScrollViewer |
||||
<StackPanel Orientation="Vertical"/> |
Name="PART_ScrollViewer" |
||||
</ItemsPanelTemplate> |
HorizontalScrollBarVisibility="{TemplateBinding (ScrollViewer.HorizontalScrollBarVisibility)}" |
||||
</TabStrip.ItemsPanel> |
VerticalScrollBarVisibility="{TemplateBinding (ScrollViewer.VerticalScrollBarVisibility)}" |
||||
</TabStrip> |
Background="{TemplateBinding Background}"> |
||||
</ScrollViewer> |
<ItemsPresenter |
||||
<Carousel Name="PART_Content" |
Name="PART_ItemsPresenter" |
||||
Margin="8 0 0 0" |
Items="{TemplateBinding Items}" |
||||
MemberSelector="{x:Static TabControl.ContentSelector}" |
ItemsPanel="{TemplateBinding ItemsPanel}" |
||||
Items="{TemplateBinding Items}" |
ItemTemplate="{TemplateBinding ItemTemplate}" |
||||
SelectedIndex="{TemplateBinding SelectedIndex}" |
MemberSelector="{TemplateBinding MemberSelector}"> |
||||
PageTransition="{TemplateBinding PageTransition}" |
</ItemsPresenter> |
||||
Grid.Row="1"/> |
</ScrollViewer> |
||||
</DockPanel> |
<ContentPresenter |
||||
</ControlTemplate> |
Name="PART_Content" |
||||
</Setter> |
Margin="{TemplateBinding Padding}" |
||||
</Style> |
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" |
||||
|
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" |
||||
|
Content="{TemplateBinding SelectedContent}" |
||||
|
ContentTemplate="{TemplateBinding SelectedContentTemplate}"> |
||||
|
</ContentPresenter> |
||||
|
</DockPanel> |
||||
|
</Border> |
||||
|
</ControlTemplate> |
||||
|
</Setter> |
||||
|
</Style> |
||||
|
|
||||
<Style Selector="TabControl.sidebar TabStripItem"> |
<Style Selector="TabControl.sidebar > TabItem"> |
||||
<Setter Property="Foreground" Value="White"/> |
<Setter Property="BorderThickness" Value="0"/> |
||||
<Setter Property="FontSize" Value="14"/> |
<Setter Property="Foreground" Value="White"/> |
||||
<Setter Property="Margin" Value="0"/> |
<Setter Property="FontSize" Value="14"/> |
||||
<Setter Property="Padding" Value="16"/> |
<Setter Property="Margin" Value="0"/> |
||||
<Setter Property="Opacity" Value="0.5"/> |
<Setter Property="Padding" Value="16"/> |
||||
<Setter Property="Transitions"> |
<Setter Property="Opacity" Value="0.5"/> |
||||
<Transitions> |
<Setter Property="Transitions"> |
||||
<DoubleTransition Property="Opacity" Duration="0:0:0.2"/> |
<Transitions> |
||||
</Transitions> |
<DoubleTransition Property="Opacity" Duration="0:0:0.5"/> |
||||
</Setter> |
</Transitions> |
||||
</Style> |
</Setter> |
||||
|
</Style> |
||||
<Style Selector="TabControl.sidebar TabStripItem:pointerover"> |
<Style Selector="TabControl.sidebar > TabItem:pointerover"> |
||||
<Setter Property="Opacity" Value="1"/> |
<Setter Property="Opacity" Value="1"/> |
||||
</Style> |
</Style> |
||||
|
<Style Selector="TabControl.sidebar > TabItem:pointerover /template/ ContentPresenter#PART_ContentPresenter"> |
||||
<Style Selector="TabControl.sidebar TabStripItem:selected"> |
<Setter Property="Background" Value="Transparent"/> |
||||
<Setter Property="Background" Value="{DynamicResource ThemeAccentBrush2}"/> |
</Style> |
||||
<Setter Property="Opacity" Value="1"/> |
<Style Selector="TabControl.sidebar > TabItem:selected"> |
||||
</Style> |
<Setter Property="Opacity" Value="1"/> |
||||
|
</Style> |
||||
|
<Style Selector="TabControl.sidebar > TabItem:selected /template/ ContentPresenter#PART_ContentPresenter"> |
||||
|
<Setter Property="Background" Value="{DynamicResource ThemeAccentBrush2}"/> |
||||
|
</Style> |
||||
</Styles> |
</Styles> |
||||
|
|||||
@ -0,0 +1,59 @@ |
|||||
|
// Copyright (c) The Avalonia Project. All rights reserved.
|
||||
|
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
||||
|
|
||||
|
using Avalonia.Controls.Primitives; |
||||
|
|
||||
|
namespace Avalonia.Controls.Generators |
||||
|
{ |
||||
|
public class TabItemContainerGenerator : ItemContainerGenerator<TabItem> |
||||
|
{ |
||||
|
public TabItemContainerGenerator(TabControl owner) |
||||
|
: base(owner, ContentControl.ContentProperty, ContentControl.ContentTemplateProperty) |
||||
|
{ |
||||
|
Owner = owner; |
||||
|
} |
||||
|
|
||||
|
public new TabControl Owner { get; } |
||||
|
|
||||
|
protected override IControl CreateContainer(object item) |
||||
|
{ |
||||
|
var tabItem = (TabItem)base.CreateContainer(item); |
||||
|
|
||||
|
tabItem.ParentTabControl = Owner; |
||||
|
|
||||
|
tabItem[~TabControl.TabStripPlacementProperty] = Owner[~TabControl.TabStripPlacementProperty]; |
||||
|
|
||||
|
if (tabItem.HeaderTemplate == null) |
||||
|
{ |
||||
|
tabItem[~HeaderedContentControl.HeaderTemplateProperty] = Owner[~ItemsControl.ItemTemplateProperty]; |
||||
|
} |
||||
|
|
||||
|
if (tabItem.Header == null) |
||||
|
{ |
||||
|
if (item is IHeadered headered) |
||||
|
{ |
||||
|
tabItem.Header = headered.Header; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
if (!(tabItem.DataContext is IControl)) |
||||
|
{ |
||||
|
tabItem.Header = tabItem.DataContext; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (!(tabItem.Content is IControl)) |
||||
|
{ |
||||
|
tabItem[~ContentControl.ContentTemplateProperty] = Owner[~TabControl.ContentTemplateProperty]; |
||||
|
} |
||||
|
|
||||
|
if (tabItem.Content == null) |
||||
|
{ |
||||
|
tabItem[~ContentControl.ContentProperty] = tabItem[~StyledElement.DataContextProperty]; |
||||
|
} |
||||
|
|
||||
|
return tabItem; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,124 @@ |
|||||
|
using System; |
||||
|
using Avalonia.Media; |
||||
|
|
||||
|
namespace Avalonia.Controls |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Viewbox is used to scale single child.
|
||||
|
/// </summary>
|
||||
|
/// <seealso cref="Avalonia.Controls.Decorator" />
|
||||
|
public class Viewbox : Decorator |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// The stretch property
|
||||
|
/// </summary>
|
||||
|
public static AvaloniaProperty<Stretch> StretchProperty = |
||||
|
AvaloniaProperty.RegisterDirect<Viewbox, Stretch>(nameof(Stretch), |
||||
|
v => v.Stretch, (c, v) => c.Stretch = v, Stretch.Uniform); |
||||
|
|
||||
|
private Stretch _stretch = Stretch.Uniform; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets the stretch mode,
|
||||
|
/// which determines how child fits into the available space.
|
||||
|
/// </summary>
|
||||
|
/// <value>
|
||||
|
/// The stretch.
|
||||
|
/// </value>
|
||||
|
public Stretch Stretch |
||||
|
{ |
||||
|
get => _stretch; |
||||
|
set => SetAndRaise(StretchProperty, ref _stretch, value); |
||||
|
} |
||||
|
|
||||
|
static Viewbox() |
||||
|
{ |
||||
|
ClipToBoundsProperty.OverrideDefaultValue<Viewbox>(true); |
||||
|
AffectsMeasure<Viewbox>(StretchProperty); |
||||
|
} |
||||
|
|
||||
|
protected override Size MeasureOverride(Size availableSize) |
||||
|
{ |
||||
|
var child = Child; |
||||
|
|
||||
|
if (child != null) |
||||
|
{ |
||||
|
child.Measure(Size.Infinity); |
||||
|
|
||||
|
var childSize = child.DesiredSize; |
||||
|
|
||||
|
var scale = GetScale(availableSize, childSize, Stretch); |
||||
|
|
||||
|
return childSize * scale; |
||||
|
} |
||||
|
|
||||
|
return new Size(); |
||||
|
} |
||||
|
|
||||
|
protected override Size ArrangeOverride(Size finalSize) |
||||
|
{ |
||||
|
var child = Child; |
||||
|
|
||||
|
if (child != null) |
||||
|
{ |
||||
|
var childSize = child.DesiredSize; |
||||
|
var scale = GetScale(finalSize, childSize, Stretch); |
||||
|
var scaleTransform = child.RenderTransform as ScaleTransform; |
||||
|
|
||||
|
if (scaleTransform == null) |
||||
|
{ |
||||
|
child.RenderTransform = scaleTransform = new ScaleTransform(scale.X, scale.Y); |
||||
|
child.RenderTransformOrigin = RelativePoint.TopLeft; |
||||
|
} |
||||
|
|
||||
|
scaleTransform.ScaleX = scale.X; |
||||
|
scaleTransform.ScaleY = scale.Y; |
||||
|
|
||||
|
child.Arrange(new Rect(childSize)); |
||||
|
|
||||
|
return childSize * scale; |
||||
|
} |
||||
|
|
||||
|
return new Size(); |
||||
|
} |
||||
|
|
||||
|
private static Vector GetScale(Size availableSize, Size childSize, Stretch stretch) |
||||
|
{ |
||||
|
double scaleX = 1.0; |
||||
|
double scaleY = 1.0; |
||||
|
|
||||
|
bool validWidth = !double.IsPositiveInfinity(availableSize.Width); |
||||
|
bool validHeight = !double.IsPositiveInfinity(availableSize.Height); |
||||
|
|
||||
|
if (stretch != Stretch.None && (validWidth || validHeight)) |
||||
|
{ |
||||
|
scaleX = childSize.Width <= 0.0 ? 0.0 : availableSize.Width / childSize.Width; |
||||
|
scaleY = childSize.Height <= 0.0 ? 0.0 : availableSize.Height / childSize.Height; |
||||
|
|
||||
|
if (!validWidth) |
||||
|
{ |
||||
|
scaleX = scaleY; |
||||
|
} |
||||
|
else if (!validHeight) |
||||
|
{ |
||||
|
scaleY = scaleX; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
switch (stretch) |
||||
|
{ |
||||
|
case Stretch.Uniform: |
||||
|
scaleX = scaleY = Math.Min(scaleX, scaleY); |
||||
|
break; |
||||
|
|
||||
|
case Stretch.UniformToFill: |
||||
|
scaleX = scaleY = Math.Max(scaleX, scaleY); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return new Vector(scaleX, scaleY); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,13 +0,0 @@ |
|||||
<Style xmlns="https://github.com/avaloniaui" Selector="LayoutTransformControl"> |
|
||||
<Setter Property="Template"> |
|
||||
<ControlTemplate> |
|
||||
<ContentPresenter Name="PART_ContentPresenter" |
|
||||
Background="{TemplateBinding Background}" |
|
||||
BorderBrush="{TemplateBinding BorderBrush}" |
|
||||
BorderThickness="{TemplateBinding BorderThickness}" |
|
||||
ContentTemplate="{TemplateBinding ContentTemplate}" |
|
||||
Content="{TemplateBinding Content}" |
|
||||
Padding="{TemplateBinding Padding}"/> |
|
||||
</ControlTemplate> |
|
||||
</Setter> |
|
||||
</Style> |
|
||||
@ -1,50 +1,63 @@ |
|||||
<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> |
<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> |
||||
<Style Selector="TabControl"> |
<Style Selector="TabControl"> |
||||
<Setter Property="Template"> |
<Setter Property="Template"> |
||||
<ControlTemplate> |
<ControlTemplate> |
||||
<Border Background="{TemplateBinding Background}" |
<Border |
||||
BorderBrush="{TemplateBinding BorderBrush}" |
Margin="{TemplateBinding Margin}" |
||||
BorderThickness="{TemplateBinding BorderThickness}"> |
BorderBrush="{TemplateBinding BorderBrush}" |
||||
<DockPanel> |
BorderThickness="{TemplateBinding BorderThickness}" |
||||
<TabStrip Name="PART_TabStrip" |
Background="{TemplateBinding Background}" |
||||
MemberSelector="{x:Static TabControl.HeaderSelector}" |
HorizontalAlignment="{TemplateBinding HorizontalAlignment}" |
||||
Items="{TemplateBinding Items}" |
VerticalAlignment="{TemplateBinding VerticalAlignment}"> |
||||
SelectedIndex="{TemplateBinding SelectedIndex, Mode=TwoWay}"/> |
<DockPanel> |
||||
<Carousel Name="PART_Content" |
<ItemsPresenter |
||||
MemberSelector="{x:Static TabControl.ContentSelector}" |
Name="PART_ItemsPresenter" |
||||
Items="{TemplateBinding Items}" |
Items="{TemplateBinding Items}" |
||||
SelectedIndex="{TemplateBinding SelectedIndex}" |
ItemsPanel="{TemplateBinding ItemsPanel}" |
||||
PageTransition="{TemplateBinding PageTransition}" |
ItemTemplate="{TemplateBinding ItemTemplate}" |
||||
Grid.Row="1"/> |
MemberSelector="{TemplateBinding MemberSelector}" > |
||||
</DockPanel> |
</ItemsPresenter> |
||||
</Border> |
<ContentPresenter |
||||
</ControlTemplate> |
Name="PART_Content" |
||||
</Setter> |
Margin="{TemplateBinding Padding}" |
||||
</Style> |
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" |
||||
<Style Selector="TabControl[TabStripPlacement=Top] /template/ TabStrip"> |
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" |
||||
<Setter Property="DockPanel.Dock" Value="Top"/> |
Content="{TemplateBinding SelectedContent}" |
||||
</Style> |
ContentTemplate="{TemplateBinding SelectedContentTemplate}"> |
||||
<Style Selector="TabControl[TabStripPlacement=Bottom] /template/ TabStrip"> |
</ContentPresenter> |
||||
<Setter Property="DockPanel.Dock" Value="Bottom"/> |
</DockPanel> |
||||
</Style> |
</Border> |
||||
<Style Selector="TabControl[TabStripPlacement=Left] /template/ TabStrip"> |
</ControlTemplate> |
||||
<Setter Property="DockPanel.Dock" Value="Left"/> |
</Setter> |
||||
<Setter Property="ItemsPanel"> |
</Style> |
||||
<Setter.Value> |
<Style Selector="TabControl[TabStripPlacement=Top]"> |
||||
<ItemsPanelTemplate> |
<Setter Property="Padding" Value="0 4 0 0"/> |
||||
<StackPanel Orientation="Vertical"/> |
</Style> |
||||
</ItemsPanelTemplate> |
<Style Selector="TabControl[TabStripPlacement=Top] /template/ ItemsPresenter#PART_ItemsPresenter"> |
||||
</Setter.Value> |
<Setter Property="DockPanel.Dock" Value="Top"/> |
||||
</Setter> |
</Style> |
||||
</Style> |
<Style Selector="TabControl[TabStripPlacement=Bottom] /template/ ItemsPresenter#PART_ItemsPresenter"> |
||||
<Style Selector="TabControl[TabStripPlacement=Right] /template/ TabStrip"> |
<Setter Property="DockPanel.Dock" Value="Bottom"/> |
||||
<Setter Property="DockPanel.Dock" Value="Right"/> |
</Style> |
||||
<Setter Property="ItemsPanel"> |
<Style Selector="TabControl[TabStripPlacement=Bottom]"> |
||||
<Setter.Value> |
<Setter Property="Padding" Value="0 0 0 4"/> |
||||
<ItemsPanelTemplate> |
</Style> |
||||
<StackPanel Orientation="Vertical"/> |
<Style Selector="TabControl[TabStripPlacement=Left] /template/ ItemsPresenter#PART_ItemsPresenter"> |
||||
</ItemsPanelTemplate> |
<Setter Property="DockPanel.Dock" Value="Left"/> |
||||
</Setter.Value> |
</Style> |
||||
</Setter> |
<Style Selector="TabControl[TabStripPlacement=Left] /template/ ItemsPresenter#PART_ItemsPresenter > WrapPanel"> |
||||
</Style> |
<Setter Property="Orientation" Value="Vertical"/> |
||||
</Styles> |
</Style> |
||||
|
<Style Selector="TabControl[TabStripPlacement=Left]"> |
||||
|
<Setter Property="Padding" Value="4 0 0 0"/> |
||||
|
</Style> |
||||
|
<Style Selector="TabControl[TabStripPlacement=Right] /template/ ItemsPresenter#PART_ItemsPresenter"> |
||||
|
<Setter Property="DockPanel.Dock" Value="Right"/> |
||||
|
</Style> |
||||
|
<Style Selector="TabControl[TabStripPlacement=Right] /template/ ItemsPresenter#PART_ItemsPresenter > WrapPanel"> |
||||
|
<Setter Property="Orientation" Value="Vertical"/> |
||||
|
</Style> |
||||
|
<Style Selector="TabControl[TabStripPlacement=Right]"> |
||||
|
<Setter Property="Padding" Value="0 0 0 4"/> |
||||
|
</Style> |
||||
|
</Styles> |
||||
|
|||||
@ -0,0 +1,45 @@ |
|||||
|
<Styles xmlns="https://github.com/avaloniaui"> |
||||
|
<Style Selector="TabItem"> |
||||
|
<Setter Property="Background" Value="Transparent"/> |
||||
|
<Setter Property="FontSize" Value="{DynamicResource FontSizeLarge}"/> |
||||
|
<Setter Property="Foreground" Value="{DynamicResource ThemeForegroundLightBrush}"/> |
||||
|
<Setter Property="HorizontalContentAlignment" Value="Left"/> |
||||
|
<Setter Property="Padding" Value="8"/> |
||||
|
<Setter Property="Template"> |
||||
|
<ControlTemplate> |
||||
|
<ContentPresenter |
||||
|
Name="PART_ContentPresenter" |
||||
|
Background="{TemplateBinding Background}" |
||||
|
BorderBrush="{TemplateBinding BorderBrush}" |
||||
|
BorderThickness="{TemplateBinding BorderThickness}" |
||||
|
ContentTemplate="{TemplateBinding HeaderTemplate}" |
||||
|
Content="{TemplateBinding Header}" |
||||
|
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" |
||||
|
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" |
||||
|
Margin="{TemplateBinding Margin}" |
||||
|
Padding="{TemplateBinding Padding}"/> |
||||
|
</ControlTemplate> |
||||
|
</Setter> |
||||
|
</Style> |
||||
|
<Style Selector="TabItem:disabled"> |
||||
|
<Setter Property="Opacity" Value="{DynamicResource ThemeDisabledOpacity}"/> |
||||
|
</Style> |
||||
|
<Style Selector="TabItem:pointerover /template/ ContentPresenter#PART_ContentPresenter"> |
||||
|
<Setter Property="Background" Value="{DynamicResource ThemeControlHighlightMidBrush}"/> |
||||
|
</Style> |
||||
|
<Style Selector="TabItem:selected /template/ ContentPresenter#PART_ContentPresenter"> |
||||
|
<Setter Property="Background" Value="{DynamicResource ThemeAccentBrush4}"/> |
||||
|
</Style> |
||||
|
<Style Selector="TabItem:selected:focus /template/ ContentPresenter#PART_ContentPresenter"> |
||||
|
<Setter Property="Background" Value="{DynamicResource ThemeAccentBrush3}"/> |
||||
|
</Style> |
||||
|
<Style Selector="TabItem:selected:pointerover /template/ ContentPresenter#PART_ContentPresenter"> |
||||
|
<Setter Property="Background" Value="{DynamicResource ThemeAccentBrush3}"/> |
||||
|
</Style> |
||||
|
<Style Selector="TabItem:selected:focus:pointerover /template/ ContentPresenter#PART_ContentPresenter"> |
||||
|
<Setter Property="Background" Value="{DynamicResource ThemeAccentBrush2}"/> |
||||
|
</Style> |
||||
|
<Style Selector="TabItem[TabStripPlacement=Right]"> |
||||
|
<Setter Property="HorizontalContentAlignment" Value="Right"/> |
||||
|
</Style> |
||||
|
</Styles> |
||||
@ -0,0 +1,105 @@ |
|||||
|
using Avalonia.Controls.Shapes; |
||||
|
using Avalonia.Media; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Avalonia.Controls.UnitTests |
||||
|
{ |
||||
|
public class ViewboxTests |
||||
|
{ |
||||
|
[Fact] |
||||
|
public void Viewbox_Stretch_Uniform_Child() |
||||
|
{ |
||||
|
var target = new Viewbox() { Child = new Rectangle() { Width = 100, Height = 50 } }; |
||||
|
|
||||
|
target.Measure(new Size(200, 200)); |
||||
|
target.Arrange(new Rect(new Point(0, 0), target.DesiredSize)); |
||||
|
|
||||
|
Assert.Equal(new Size(200, 100), target.DesiredSize); |
||||
|
var scaleTransform = target.Child.RenderTransform as ScaleTransform; |
||||
|
|
||||
|
Assert.NotNull(scaleTransform); |
||||
|
Assert.Equal(2.0, scaleTransform.ScaleX); |
||||
|
Assert.Equal(2.0, scaleTransform.ScaleY); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Viewbox_Stretch_None_Child() |
||||
|
{ |
||||
|
var target = new Viewbox() { Stretch = Stretch.None, Child = new Rectangle() { Width = 100, Height = 50 } }; |
||||
|
|
||||
|
target.Measure(new Size(200, 200)); |
||||
|
target.Arrange(new Rect(new Point(0, 0), target.DesiredSize)); |
||||
|
|
||||
|
Assert.Equal(new Size(100, 50), target.DesiredSize); |
||||
|
var scaleTransform = target.Child.RenderTransform as ScaleTransform; |
||||
|
|
||||
|
Assert.NotNull(scaleTransform); |
||||
|
Assert.Equal(1.0, scaleTransform.ScaleX); |
||||
|
Assert.Equal(1.0, scaleTransform.ScaleY); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Viewbox_Stretch_Fill_Child() |
||||
|
{ |
||||
|
var target = new Viewbox() { Stretch = Stretch.Fill, Child = new Rectangle() { Width = 100, Height = 50 } }; |
||||
|
|
||||
|
target.Measure(new Size(200, 200)); |
||||
|
target.Arrange(new Rect(new Point(0, 0), target.DesiredSize)); |
||||
|
|
||||
|
Assert.Equal(new Size(200, 200), target.DesiredSize); |
||||
|
var scaleTransform = target.Child.RenderTransform as ScaleTransform; |
||||
|
|
||||
|
Assert.NotNull(scaleTransform); |
||||
|
Assert.Equal(2.0, scaleTransform.ScaleX); |
||||
|
Assert.Equal(4.0, scaleTransform.ScaleY); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Viewbox_Stretch_UniformToFill_Child() |
||||
|
{ |
||||
|
var target = new Viewbox() { Stretch = Stretch.UniformToFill, Child = new Rectangle() { Width = 100, Height = 50 } }; |
||||
|
|
||||
|
target.Measure(new Size(200, 200)); |
||||
|
target.Arrange(new Rect(new Point(0, 0), target.DesiredSize)); |
||||
|
|
||||
|
Assert.Equal(new Size(200, 200), target.DesiredSize); |
||||
|
var scaleTransform = target.Child.RenderTransform as ScaleTransform; |
||||
|
|
||||
|
Assert.NotNull(scaleTransform); |
||||
|
Assert.Equal(4.0, scaleTransform.ScaleX); |
||||
|
Assert.Equal(4.0, scaleTransform.ScaleY); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Viewbox_Stretch_Uniform_Child_With_Unrestricted_Width() |
||||
|
{ |
||||
|
var target = new Viewbox() { Child = new Rectangle() { Width = 100, Height = 50 } }; |
||||
|
|
||||
|
target.Measure(new Size(double.PositiveInfinity, 200)); |
||||
|
target.Arrange(new Rect(new Point(0, 0), target.DesiredSize)); |
||||
|
|
||||
|
Assert.Equal(new Size(400, 200), target.DesiredSize); |
||||
|
var scaleTransform = target.Child.RenderTransform as ScaleTransform; |
||||
|
|
||||
|
Assert.NotNull(scaleTransform); |
||||
|
Assert.Equal(4.0, scaleTransform.ScaleX); |
||||
|
Assert.Equal(4.0, scaleTransform.ScaleY); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Viewbox_Stretch_Uniform_Child_With_Unrestricted_Height() |
||||
|
{ |
||||
|
var target = new Viewbox() { Child = new Rectangle() { Width = 100, Height = 50 } }; |
||||
|
|
||||
|
target.Measure(new Size(200, double.PositiveInfinity)); |
||||
|
target.Arrange(new Rect(new Point(0, 0), target.DesiredSize)); |
||||
|
|
||||
|
Assert.Equal(new Size(200, 100), target.DesiredSize); |
||||
|
var scaleTransform = target.Child.RenderTransform as ScaleTransform; |
||||
|
|
||||
|
Assert.NotNull(scaleTransform); |
||||
|
Assert.Equal(2.0, scaleTransform.ScaleX); |
||||
|
Assert.Equal(2.0, scaleTransform.ScaleY); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue