Files
Ursa.Avalonia/demo/Ursa.Demo/Pages/FormDemo.axaml

82 lines
4.5 KiB
XML

<UserControl
x:Class="Ursa.Demo.Pages.FormDemo"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:common="clr-namespace:Ursa.Common;assembly=Ursa"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:u="https://irihi.tech/ursa"
xmlns:vm="clr-namespace:Ursa.Demo.ViewModels;assembly=Ursa.Demo"
xmlns:converters="clr-namespace:Ursa.Demo.Converters"
d:DesignHeight="450"
d:DesignWidth="800"
x:CompileBindings="True"
x:DataType="vm:FormDemoViewModel"
mc:Ignorable="d">
<ScrollViewer>
<StackPanel HorizontalAlignment="Left" Margin="24 0 0 0 ">
<u:Divider Content="Simple Form"/>
<u:Form LabelPosition="Left" LabelWidth="*">
<TextBox Width="300" u:FormItem.Label="Name" u:FormItem.IsRequired="True" />
<TextBox Width="300" u:FormItem.Label="Email" />
<TextBox Width="300" u:FormItem.Label="Message" Classes="TextArea"/>
</u:Form>
<u:Divider Content="Form accessibility"/>
<u:Form LabelPosition="Left" LabelWidth="*">
<TextBox Width="300" u:FormItem.Label="_Name" />
<TextBox Width="300" u:FormItem.Label="_Email" />
<TextBox Width="300" u:FormItem.Label="_Message" Classes="TextArea"/>
</u:Form>
<u:Divider Content="Label on top"/>
<u:Form LabelPosition="Top" LabelWidth="*">
<TextBox Width="300" u:FormItem.Label="Name" />
<TextBox Width="300" u:FormItem.Label="Email" />
</u:Form>
<u:Divider Content="FormGroup"/>
<u:Form LabelPosition="Left" LabelWidth="*">
<u:FormGroup Header="Basic Information">
<TextBox Width="300" u:FormItem.Label="Name" />
<TextBox Width="300" u:FormItem.Label="Email" />
</u:FormGroup>
<u:FormGroup Header="Education Information">
<TextBox Width="300" u:FormItem.Label="Collage" />
<u:FormItem Label="Study Time">
<u:DateRangePicker Width="300"></u:DateRangePicker>
</u:FormItem>
</u:FormGroup>
<Button Content="Submit" Theme="{DynamicResource SolidButton}" u:FormItem.NoLabel="True" HorizontalAlignment="Stretch"/>
</u:Form>
<u:Divider Content="MVVM setup and validation" />
<u:Form LabelPosition="Left" LabelWidth="*" DataContext="{Binding Model}">
<TextBox Width="300" u:FormItem.Label="Name" Text="{Binding Name}"/>
<TextBox Width="300" u:FormItem.Label="Email" Text="{Binding Email}" />
</u:Form>
<u:Divider Content="MVVM setup for dynamic items. " />
<u:Form ItemsSource="{Binding FormGroups}" HorizontalAlignment="Stretch" LabelPosition="Left" LabelWidth="*">
<u:Form.Styles>
<Style Selector="u|FormGroup" x:DataType="vm:IFormGroupViewModel">
<Setter Property="Header" Value="{Binding Title}" />
<Setter Property="ItemsSource" Value="{Binding Items}" />
</Style>
<Style Selector="u|FormItem" x:DataType="vm:IFromItemViewModel">
<Setter Property="Label" Value="{Binding Label}" />
</Style>
</u:Form.Styles>
<u:Form.ItemTemplate>
<converters:FormDataTemplateSelector>
<DataTemplate x:Key="{x:Type vm:FormTextViewModel}" DataType="vm:FormTextViewModel">
<TextBox Text="{Binding Value}"/>
</DataTemplate>
<DataTemplate x:Key="{x:Type vm:FormAgeViewModel}" DataType="vm:FormAgeViewModel">
<u:NumericUIntUpDown Value="{Binding Age}"/>
</DataTemplate>
<DataTemplate x:Key="{x:Type vm:FormDateRangeViewModel}" DataType="vm:FormDateRangeViewModel">
<u:DateRangePicker SelectedStartDate="{Binding Start}" SelectedEndDate="{Binding End}"/>
</DataTemplate>
</converters:FormDataTemplateSelector>
</u:Form.ItemTemplate>
</u:Form>
</StackPanel>
</ScrollViewer>
</UserControl>