4 changed files with 214 additions and 0 deletions
@ -0,0 +1,96 @@ |
|||||
|
<UserControl xmlns="https://github.com/avaloniaui" |
||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> |
||||
|
<StackPanel Orientation="Vertical" Gap="4"> |
||||
|
<TextBlock Margin="2" Classes="h1">Numeric up-down controls</TextBlock> |
||||
|
<TextBlock Margin="2" Classes="h2" TextWrapping="Wrap">Numeric up-down controls provide a TextBox with button spinners that allow incrementing and decrementing numeric values by using the spinner buttons, keyboard up/down arrows, or mouse wheel.</TextBlock> |
||||
|
<TextBlock Margin="2" Classes="h2">The following controls are available to support various native numeric types:</TextBlock> |
||||
|
<TextBlock Margin="2" Classes="h2">ByteUpDown, ShortUpDown, IntegerUpDown, LongUpDown, SingleUpDown, DoubleUpDown, DecimalUpDown.</TextBlock> |
||||
|
|
||||
|
<TextBlock Margin="2,5,2,2" FontSize="14" FontWeight="Bold">Features:</TextBlock> |
||||
|
<Grid Margin="2" ColumnDefinitions="Auto,Auto,Auto,Auto" RowDefinitions="Auto,Auto"> |
||||
|
<Grid Grid.Row="0" Grid.Column="0" ColumnDefinitions="Auto, Auto" RowDefinitions="35,35,35,35,35"> |
||||
|
<TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" Margin="2">ShowButtonSpinner:</TextBlock> |
||||
|
<CheckBox Grid.Row="0" Grid.Column="1" IsChecked="{Binding #doubleUpDown.ShowButtonSpinner}" VerticalAlignment="Center" Margin="2"/> |
||||
|
|
||||
|
<TextBlock Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" Margin="2">IsReadOnly:</TextBlock> |
||||
|
<CheckBox Grid.Row="1" Grid.Column="1" IsChecked="{Binding #doubleUpDown.IsReadOnly}" VerticalAlignment="Center" Margin="2"/> |
||||
|
|
||||
|
<TextBlock Grid.Row="2" Grid.Column="0" VerticalAlignment="Center" Margin="2">AllowSpin:</TextBlock> |
||||
|
<CheckBox Grid.Row="2" Grid.Column="1" IsChecked="{Binding #doubleUpDown.AllowSpin}" IsEnabled="{Binding #doubleUpDown.!IsReadOnly}" VerticalAlignment="Center" Margin="2"/> |
||||
|
|
||||
|
<TextBlock Grid.Row="3" Grid.Column="0" VerticalAlignment="Center" Margin="2">ClipValueToMinMax:</TextBlock> |
||||
|
<CheckBox Grid.Row="3" Grid.Column="1" IsChecked="{Binding #doubleUpDown.ClipValueToMinMax}" VerticalAlignment="Center" Margin="2"/> |
||||
|
|
||||
|
<TextBlock Grid.Row="4" Grid.Column="0" VerticalAlignment="Center" Margin="2">DisplayDefaultValueOnEmptyText:</TextBlock> |
||||
|
<CheckBox Grid.Row="4" Grid.Column="1" IsChecked="{Binding #doubleUpDown.DisplayDefaultValueOnEmptyText}" VerticalAlignment="Center" Margin="2"/> |
||||
|
</Grid> |
||||
|
<Grid Grid.Row="0" Grid.Column="1" Margin="10,2,2,2" ColumnDefinitions="Auto, 120" RowDefinitions="35,35,35,35,35"> |
||||
|
<TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" Margin="2">FormatString:</TextBlock> |
||||
|
<DropDown Grid.Row="0" Grid.Column="1" Items="{Binding Formats}" SelectedItem="{Binding SelectedFormat}" |
||||
|
VerticalAlignment="Center" Margin="2"> |
||||
|
<DropDown.ItemTemplate> |
||||
|
<DataTemplate> |
||||
|
<StackPanel Orientation="Horizontal" Gap="2"> |
||||
|
<TextBlock Text="{Binding Name}"/> |
||||
|
<TextBlock Text="-"/> |
||||
|
<TextBlock Text="{Binding Value}"/> |
||||
|
</StackPanel> |
||||
|
</DataTemplate> |
||||
|
</DropDown.ItemTemplate> |
||||
|
</DropDown> |
||||
|
|
||||
|
<TextBlock Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" Margin="2">ButtonSpinnerLocation:</TextBlock> |
||||
|
<DropDown Grid.Row="1" Grid.Column="1" Items="{Binding SpinnerLocations}" SelectedItem="{Binding #doubleUpDown.ButtonSpinnerLocation}" |
||||
|
VerticalAlignment="Center" Margin="2"/> |
||||
|
|
||||
|
<TextBlock Grid.Row="2" Grid.Column="0" VerticalAlignment="Center" Margin="2">CultureInfo:</TextBlock> |
||||
|
<DropDown Grid.Row="2" Grid.Column="1" Items="{Binding Cultures}" SelectedItem="{Binding #doubleUpDown.CultureInfo}" |
||||
|
VerticalAlignment="Center" Margin="2"/> |
||||
|
|
||||
|
<TextBlock Grid.Row="3" Grid.Column="0" VerticalAlignment="Center" Margin="2">Watermark:</TextBlock> |
||||
|
<TextBox Grid.Row="3" Grid.Column="1" Text="{Binding #doubleUpDown.Watermark}" VerticalAlignment="Center" Margin="2" /> |
||||
|
|
||||
|
<TextBlock Grid.Row="4" Grid.Column="0" VerticalAlignment="Center" Margin="2">Text:</TextBlock> |
||||
|
<TextBox Grid.Row="4" Grid.Column="1" Text="{Binding #doubleUpDown.Text}" VerticalAlignment="Center" Margin="2" /> |
||||
|
</Grid> |
||||
|
<Grid Grid.Row="0" Grid.Column="2" Margin="10,2,2,2" RowDefinitions="35,35,35,35,35" ColumnDefinitions="Auto, 120"> |
||||
|
<TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" Margin="10,2,2,2">Minimum:</TextBlock> |
||||
|
<DoubleUpDown Grid.Row="0" Grid.Column="1" Value="{Binding #doubleUpDown.Minimum}" AllowInputSpecialValues="NegativeInfinity" |
||||
|
CultureInfo="{Binding #doubleUpDown.CultureInfo}" VerticalAlignment="Center" Height="25" Margin="2" Width="70" HorizontalAlignment="Center"/> |
||||
|
|
||||
|
<TextBlock Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" Margin="10,2,2,2">Maximum:</TextBlock> |
||||
|
<DoubleUpDown Grid.Row="1" Grid.Column="1" Value="{Binding #doubleUpDown.Maximum}" AllowInputSpecialValues="PositiveInfinity" |
||||
|
CultureInfo="{Binding #doubleUpDown.CultureInfo}" VerticalAlignment="Center" Height="25" Margin="2" Width="70" HorizontalAlignment="Center"/> |
||||
|
|
||||
|
<TextBlock Grid.Row="2" Grid.Column="0" VerticalAlignment="Center" Margin="10,2,2,2">Increment:</TextBlock> |
||||
|
<DoubleUpDown Grid.Row="2" Grid.Column="1" Value="{Binding #doubleUpDown.Increment}" VerticalAlignment="Center" |
||||
|
Height="25" Margin="2" Width="70" HorizontalAlignment="Center"/> |
||||
|
|
||||
|
<TextBlock Grid.Row="3" Grid.Column="0" VerticalAlignment="Center" Margin="10,2,2,2">Value:</TextBlock> |
||||
|
<DoubleUpDown Grid.Row="3" Grid.Column="1" Value="{Binding #doubleUpDown.Value}" VerticalAlignment="Center" |
||||
|
Height="25" Margin="2" Width="70" HorizontalAlignment="Center"/> |
||||
|
|
||||
|
<TextBlock Grid.Row="4" Grid.Column="0" VerticalAlignment="Center" Margin="10,2,2,2">DefaultValue:</TextBlock> |
||||
|
<DoubleUpDown Grid.Row="4" Grid.Column="1" Value="{Binding #doubleUpDown.DefaultValue}" AllowInputSpecialValues="Any" |
||||
|
VerticalAlignment="Center" Height="25" Margin="2" Width="70" HorizontalAlignment="Center"/> |
||||
|
|
||||
|
</Grid> |
||||
|
</Grid> |
||||
|
|
||||
|
<TextBlock Margin="2" Classes="h2">DoubleUpDown and SingleUpDown support the AllowInputSpecialValues property</TextBlock> |
||||
|
<StackPanel Orientation="Horizontal"> |
||||
|
<TextBlock Grid.Row="4" Grid.Column="0" VerticalAlignment="Center" Margin="2">AllowInputSpecialValues:</TextBlock> |
||||
|
<DropDown Grid.Row="1" Grid.Column="1" Items="{Binding AllowedSpecialValues}" SelectedItem="{Binding #doubleUpDown.AllowInputSpecialValues}" |
||||
|
VerticalAlignment="Center" Margin="2"/> |
||||
|
</StackPanel> |
||||
|
|
||||
|
<StackPanel Margin="2,10,2,2" Orientation="Horizontal" Gap="10"> |
||||
|
<TextBlock FontSize="14" FontWeight="Bold" VerticalAlignment="Center">Usage of DoubleUpDown:</TextBlock> |
||||
|
<DoubleUpDown Name="doubleUpDown" Minimum="0" Maximum="10" Increment="0.5" |
||||
|
AllowInputSpecialValues="Any" CultureInfo="en-US" |
||||
|
VerticalAlignment="Center" Height="25" Width="100" |
||||
|
Watermark="Enter text" FormatString="{Binding SelectedFormat.Value}"/> |
||||
|
</StackPanel> |
||||
|
|
||||
|
</StackPanel> |
||||
|
</UserControl> |
||||
@ -0,0 +1,111 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Globalization; |
||||
|
using System.Linq; |
||||
|
using Avalonia; |
||||
|
using Avalonia.Controls; |
||||
|
using Avalonia.Controls.Primitives; |
||||
|
using Avalonia.Markup.Xaml; |
||||
|
using ReactiveUI; |
||||
|
|
||||
|
namespace ControlCatalog.Pages |
||||
|
{ |
||||
|
public class NumbersPage : UserControl |
||||
|
{ |
||||
|
public NumbersPage() |
||||
|
{ |
||||
|
this.InitializeComponent(); |
||||
|
var viewModel = new NumbersPageViewModel(); |
||||
|
DataContext = viewModel; |
||||
|
} |
||||
|
|
||||
|
private void InitializeComponent() |
||||
|
{ |
||||
|
AvaloniaXamlLoader.Load(this); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public class NumbersPageViewModel : ReactiveObject |
||||
|
{ |
||||
|
private IList<FormatObject> _formats; |
||||
|
private FormatObject _selectedFormat; |
||||
|
private IList<Location> _spinnerLocations; |
||||
|
private IList<AllowedSpecialValues> _allowedSpecialValues; |
||||
|
|
||||
|
public NumbersPageViewModel() |
||||
|
{ |
||||
|
SelectedFormat = Formats.FirstOrDefault(); |
||||
|
} |
||||
|
|
||||
|
public IList<FormatObject> Formats |
||||
|
{ |
||||
|
get |
||||
|
{ |
||||
|
return _formats ?? (_formats = new List<FormatObject>() |
||||
|
{ |
||||
|
new FormatObject() {Name = "Currency", Value = "C2"}, |
||||
|
new FormatObject() {Name = "Fixed point", Value = "F2"}, |
||||
|
new FormatObject() {Name = "General", Value = "G"}, |
||||
|
new FormatObject() {Name = "Number", Value = "N"}, |
||||
|
new FormatObject() {Name = "Percent", Value = "P"}, |
||||
|
new FormatObject() {Name = "Degrees", Value = "{0:N2} °"}, |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public IList<Location> SpinnerLocations |
||||
|
{ |
||||
|
get |
||||
|
{ |
||||
|
if (_spinnerLocations == null) |
||||
|
{ |
||||
|
_spinnerLocations = new List<Location>(); |
||||
|
foreach (Location value in Enum.GetValues(typeof(Location))) |
||||
|
{ |
||||
|
_spinnerLocations.Add(value); |
||||
|
} |
||||
|
} |
||||
|
return _spinnerLocations ; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public IList<CultureInfo> Cultures { get; } = new List<CultureInfo>() |
||||
|
{ |
||||
|
new CultureInfo("en-US"), |
||||
|
new CultureInfo("en-GB"), |
||||
|
new CultureInfo("fr-FR"), |
||||
|
new CultureInfo("ar-DZ"), |
||||
|
new CultureInfo("zh-CN"), |
||||
|
new CultureInfo("cs-CZ") |
||||
|
}; |
||||
|
|
||||
|
public IList<AllowedSpecialValues> AllowedSpecialValues |
||||
|
{ |
||||
|
get |
||||
|
{ |
||||
|
if (_allowedSpecialValues == null) |
||||
|
{ |
||||
|
_allowedSpecialValues = new List<AllowedSpecialValues>(); |
||||
|
foreach (AllowedSpecialValues value in Enum.GetValues(typeof(AllowedSpecialValues))) |
||||
|
{ |
||||
|
_allowedSpecialValues.Add(value); |
||||
|
} |
||||
|
} |
||||
|
return _allowedSpecialValues; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public FormatObject SelectedFormat |
||||
|
{ |
||||
|
get { return _selectedFormat; } |
||||
|
set { this.RaiseAndSetIfChanged(ref _selectedFormat, value); } |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public class FormatObject |
||||
|
{ |
||||
|
public string Value { get; set; } |
||||
|
public string Name { get; set; } |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue