A cross-platform UI framework for .NET
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

224 lines
14 KiB

<controls:SamplePage xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:ControlCatalog.Controls"
xmlns:pages="using:ControlCatalog.Pages"
x:Class="ControlCatalog.Pages.ButtonsPage"
Header="Buttons"
Description="Button and its relatives: buttons that toggle, repeat while held, open a flyout, or follow a link. All of them raise Click and can bind a Command.">
<controls:SamplePage.Resources>
<MenuFlyout x:Key="SharedMenuFlyout" Placement="Bottom">
<MenuItem Header="Item 1">
<MenuItem Header="Subitem 1" />
<MenuItem Header="Subitem 2" />
<MenuItem Header="Subitem 3" />
</MenuItem>
<MenuItem Header="Item 2" InputGesture="Ctrl+A" />
<MenuItem Header="Item 3" />
</MenuFlyout>
</controls:SamplePage.Resources>
<StackPanel Spacing="24">
<controls:SampleGroup Header="Overview">
<controls:SampleSection Header="Button"
Description="The standard push button. Content can be text or any control; Command and CommandParameter bind it to a view model."
Code="&lt;Button Content=&quot;Save&quot; Command=&quot;{Binding SaveCommand}&quot; /&gt;">
<StackPanel Spacing="12">
<WrapPanel ItemSpacing="8" LineSpacing="8">
<Button Name="DemoButton" Content="Standard _button" Click="OnDemoButtonClick" />
<Button Classes="accent" Content="Accent" />
<Button IsEnabled="False" Content="Disabled" />
<Button>
<StackPanel Orientation="Horizontal" Spacing="6">
<PathIcon Data="{StaticResource SearchIcon}" Width="14" Height="14" />
<TextBlock Text="With icon" />
</StackPanel>
</Button>
</WrapPanel>
<TextBlock Name="ClickStatus" Classes="sample-caption" Text="Click the first button to raise Click." />
</StackPanel>
<controls:SampleSection.Options>
<StackPanel Spacing="8">
<CheckBox Content="IsEnabled" IsChecked="{Binding #DemoButton.IsEnabled}" />
<CheckBox Content="IsDefault" IsChecked="{Binding #DemoButton.IsDefault}" />
<TextBlock Classes="sample-caption" Text="An IsDefault button is invoked by Enter anywhere on the page." />
</StackPanel>
</controls:SampleSection.Options>
</controls:SampleSection>
</controls:SampleGroup>
<controls:SampleGroup Header="Appearance">
<controls:SampleSection Header="Appearance"
Description="Border, background, foreground and letter spacing are ordinary properties. A button can also be restyled by overriding its theme resources.">
<!-- The thick-border button is taller than its neighbours, so centre the row on itself. -->
<WrapPanel ItemSpacing="8" LineSpacing="8">
<WrapPanel.Styles>
<Style Selector="Button">
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
</WrapPanel.Styles>
<Button BorderThickness="0" Content="No border" />
<Button BorderBrush="{DynamicResource CatalogAccentForeground}" Content="Border color" />
<Button BorderBrush="{DynamicResource CatalogAccentForeground}" BorderThickness="3" Content="Thick border" />
<Button Foreground="{DynamicResource CatalogAccentForeground}" Content="Foreground" />
<Button Background="{DynamicResource CatalogAccentBackground}" Content="Background" />
<Button Content="Re-themed">
<Button.Styles>
<Style>
<Style.Resources>
<SolidColorBrush x:Key="ThemeBorderMidBrush">Red</SolidColorBrush>
<SolidColorBrush x:Key="ThemeControlHighBrush">DarkRed</SolidColorBrush>
<SolidColorBrush x:Key="ButtonBorderBrush">Red</SolidColorBrush>
<SolidColorBrush x:Key="ButtonBackground">DarkRed</SolidColorBrush>
<SolidColorBrush x:Key="ButtonBackgroundPointerOver">Red</SolidColorBrush>
<SolidColorBrush x:Key="ButtonBackgroundPressed">OrangeRed</SolidColorBrush>
<SolidColorBrush x:Key="ButtonForeground">White</SolidColorBrush>
<SolidColorBrush x:Key="ButtonForegroundPointerOver">Black</SolidColorBrush>
<SolidColorBrush x:Key="ButtonForegroundPressed">Black</SolidColorBrush>
</Style.Resources>
</Style>
</Button.Styles>
</Button>
<Button LetterSpacing="-0.5" Content="Tight spacing" />
<Button LetterSpacing="2" Content="Loose spacing" />
<Button KeyboardNavigation.IsTabStop="False" Content="IsTabStop=False" />
</WrapPanel>
</controls:SampleSection>
</controls:SampleGroup>
<controls:SampleGroup Header="Features">
<controls:SampleSection Header="Commands, click modes and flyouts"
Description="Command runs an ICommand and disables the button while it cannot execute. ClickMode chooses when Click fires, HotKey invokes the button from the keyboard, and a plain Button can open a Flyout too."
Code="&lt;Button Content=&quot;Refresh&quot; HotKey=&quot;Ctrl+R&quot; ClickMode=&quot;Release&quot; Command=&quot;{Binding RefreshCommand}&quot; /&gt;">
<StackPanel Spacing="12">
<WrapPanel ItemSpacing="8" LineSpacing="8">
<Button Name="ModeButton" Content="Click mode" Click="OnModeButtonClick" />
<Button Content="Hot key: Ctrl+Shift+B" HotKey="Ctrl+Shift+B" Click="OnHotKeyButtonClick" />
<Button Content="With flyout" Flyout="{StaticResource SharedMenuFlyout}" />
<Button Content="Command" Command="{Binding $parent[controls:SamplePage].((pages:ButtonsPage)DataContext).CountCommand}" />
</WrapPanel>
<TextBlock Name="ModeStatus" Classes="sample-caption" Text="Press the first button, or press Ctrl+Shift+B." />
</StackPanel>
<controls:SampleSection.Options>
<StackPanel Spacing="8">
<TextBlock Text="ClickMode" Classes="sample-caption" />
<ComboBox SelectedItem="{Binding #ModeButton.ClickMode}" HorizontalAlignment="Stretch">
<ClickMode>Release</ClickMode>
<ClickMode>Press</ClickMode>
</ComboBox>
<CheckBox Content="Command can execute" IsChecked="{Binding $parent[controls:SamplePage].((pages:ButtonsPage)DataContext).CanCount}" />
</StackPanel>
</controls:SampleSection.Options>
</controls:SampleSection>
<controls:SampleSection Header="ToggleButton"
Description="A button that stays checked until it is clicked again. IsThreeState adds an indeterminate state to the cycle."
Code="&lt;ToggleButton Content=&quot;Bold&quot; IsChecked=&quot;{Binding IsBold}&quot; /&gt;">
<StackPanel Spacing="12">
<WrapPanel ItemSpacing="8" LineSpacing="8">
<ToggleButton Name="DemoToggle" Content="Toggle" />
<ToggleButton IsThreeState="True" Content="Three state" />
<ToggleButton IsChecked="True" IsEnabled="False" Content="Disabled" />
</WrapPanel>
<TextBlock Classes="sample-caption" Text="{Binding #DemoToggle.IsChecked, StringFormat='IsChecked: {0}'}" />
</StackPanel>
</controls:SampleSection>
<controls:SampleSection Header="RepeatButton"
Description="Raises Click repeatedly while it is held down. Delay is the pause before repeating starts and Interval the pause between repeats, both in milliseconds.">
<RepeatButton Name="DemoRepeat" Click="OnRepeatButtonClick">
<TextBlock Name="RepeatButtonTextBlock" Text="Repeat Button: 0" />
</RepeatButton>
<controls:SampleSection.Options>
<StackPanel Spacing="8">
<TextBlock Text="Delay" Classes="sample-caption" />
<NumericUpDown Value="{Binding #DemoRepeat.Delay}" Minimum="0" Maximum="2000" Increment="50" FormatString="0" />
<TextBlock Text="Interval" Classes="sample-caption" />
<NumericUpDown Value="{Binding #DemoRepeat.Interval}" Minimum="10" Maximum="1000" Increment="10" FormatString="0" />
</StackPanel>
</controls:SampleSection.Options>
</controls:SampleSection>
<controls:SampleSection Header="HyperlinkButton"
Description="A link-styled button that opens NavigateUri in the default browser and remembers whether it has been visited."
Code="&lt;HyperlinkButton Content=&quot;Avalonia Docs&quot; NavigateUri=&quot;https://docs.avaloniaui.net&quot; /&gt;">
<StackPanel Spacing="8">
<StackPanel Orientation="Horizontal" Spacing="12">
<HyperlinkButton x:Name="EnabledHyperlinkButton"
VerticalAlignment="Center"
NavigateUri="https://docs.avaloniaui.net/docs/welcome">
<TextBlock Text="Avalonia Docs" />
</HyperlinkButton>
<CheckBox IsChecked="{Binding #EnabledHyperlinkButton.IsVisited}"
Content="IsVisited"
VerticalAlignment="Center" />
</StackPanel>
<HyperlinkButton IsEnabled="False" NavigateUri="https://docs.avaloniaui.net/docs/welcome">
<TextBlock Text="Disabled link" />
</HyperlinkButton>
</StackPanel>
</controls:SampleSection>
<controls:SampleSection Header="DropDownButton"
Description="A button with a chevron that opens its Flyout. The content is free, so it can be text or a swatch."
Code="&lt;DropDownButton Content=&quot;Options&quot; Flyout=&quot;{StaticResource SharedMenuFlyout}&quot; /&gt;">
<WrapPanel ItemSpacing="8" LineSpacing="8">
<DropDownButton Flyout="{StaticResource SharedMenuFlyout}">
<TextBlock Text="Drop Down Button" />
</DropDownButton>
<DropDownButton Padding="0,0,8,0" Flyout="{StaticResource SharedMenuFlyout}">
<Border Background="Teal" Height="32" Width="32" />
</DropDownButton>
<DropDownButton IsEnabled="False" Content="Disabled" />
<DropDownButton />
</WrapPanel>
</controls:SampleSection>
<controls:SampleSection Header="SplitButton"
Description="Two parts that can be pressed separately: the primary part behaves like a Button and the secondary part opens the Flyout.">
<WrapPanel ItemSpacing="8" LineSpacing="8">
<SplitButton Flyout="{StaticResource SharedMenuFlyout}">
<TextBlock Text="Content" />
</SplitButton>
<SplitButton IsEnabled="False" Flyout="{StaticResource SharedMenuFlyout}">
<TextBlock Text="Disabled" />
</SplitButton>
<SplitButton Flyout="{StaticResource SharedMenuFlyout}" Content="Re-themed">
<SplitButton.Styles>
<Style>
<Style.Resources>
<x:Double x:Key="SplitButtonSeparatorWidth">1.5</x:Double>
<Thickness x:Key="SplitButtonBorderThemeThickness">2</Thickness>
<SolidColorBrush x:Key="SplitButtonBorderBrush">Red</SolidColorBrush>
<SolidColorBrush x:Key="SplitButtonBorderBrushPointerOver">Red</SolidColorBrush>
<SolidColorBrush x:Key="SplitButtonBorderBrushPressed">Red</SolidColorBrush>
<SolidColorBrush x:Key="SplitButtonBackground">DarkRed</SolidColorBrush>
<SolidColorBrush x:Key="SplitButtonBackgroundPointerOver">Red</SolidColorBrush>
<SolidColorBrush x:Key="SplitButtonBackgroundPressed">OrangeRed</SolidColorBrush>
<SolidColorBrush x:Key="SplitButtonForeground">White</SolidColorBrush>
<SolidColorBrush x:Key="SplitButtonForegroundPointerOver">Black</SolidColorBrush>
<SolidColorBrush x:Key="SplitButtonForegroundPressed">Black</SolidColorBrush>
</Style.Resources>
</Style>
</SplitButton.Styles>
</SplitButton>
</WrapPanel>
</controls:SampleSection>
<controls:SampleSection Header="ToggleSplitButton"
Description="Like SplitButton, but the primary part is a two-state toggle.">
<WrapPanel ItemSpacing="8" LineSpacing="8">
<ToggleSplitButton Flyout="{StaticResource SharedMenuFlyout}">
<TextBlock Text="Content" />
</ToggleSplitButton>
<ToggleSplitButton IsChecked="True" Flyout="{StaticResource SharedMenuFlyout}">
<TextBlock Text="Checked" />
</ToggleSplitButton>
<ToggleSplitButton IsChecked="True" IsEnabled="False" Flyout="{StaticResource SharedMenuFlyout}">
<TextBlock Text="Disabled" />
</ToggleSplitButton>
</WrapPanel>
</controls:SampleSection>
</controls:SampleGroup>
</StackPanel>
</controls:SamplePage>