feat: improve demo, add dynamic resource.

This commit is contained in:
rabbitism
2024-02-18 17:30:30 +08:00
parent 66835a8efa
commit a8d1073f75
7 changed files with 56 additions and 43 deletions

View File

@@ -12,17 +12,20 @@
x:CompileBindings="True" x:CompileBindings="True"
x:DataType="vm:FormDemoViewModel" x:DataType="vm:FormDemoViewModel"
mc:Ignorable="d"> mc:Ignorable="d">
<ScrollViewer>
<StackPanel> <StackPanel>
<StackPanel> <Grid RowDefinitions="Auto, Auto" ColumnDefinitions="Auto, Auto">
<u:EnumSelector <TextBlock Grid.Row="0" Grid.Column="0" Text="Label Position" VerticalAlignment="Center"></TextBlock>
<TextBlock Grid.Row="1" Grid.Column="0" Text="Label Alignment" VerticalAlignment="Center"></TextBlock>
<u:EnumSelector Grid.Row="0" Grid.Column="1"
Name="position" Name="position"
EnumType="common:Position" EnumType="common:Position"
Value="{x:Static common:Position.Top}" /> Value="{x:Static common:Position.Top}" />
<u:EnumSelector <u:EnumSelector Grid.Row="1" Grid.Column="1"
Name="alignment" Name="alignment"
EnumType="HorizontalAlignment" EnumType="HorizontalAlignment"
Value="{x:Static HorizontalAlignment.Left}" /> Value="{x:Static HorizontalAlignment.Left}" />
</StackPanel> </Grid>
<u:Form <u:Form
DataContext="{Binding Model}" DataContext="{Binding Model}"
LabelAlignment="{Binding #alignment.Value}" LabelAlignment="{Binding #alignment.Value}"
@@ -40,19 +43,16 @@
Text="{Binding Email}" /> Text="{Binding Email}" />
</u:FormGroup> </u:FormGroup>
<u:FormItem Label="Please select a Date"> <u:FormItem Label="Please select a Date">
<Calendar SelectedDate="{Binding Date}" /> <CalendarDatePicker SelectedDate="{Binding Date}" />
</u:FormItem> </u:FormItem>
<u:FormItem Label="Click to Submit"> <u:FormItem Label="Click to Submit">
<Button Content="With Label" /> <Button Content="Button With Label" />
</u:FormItem> </u:FormItem>
<CheckBox Content="I Agree User Agreement" u:FormItem.NoLabel="True"></CheckBox>
<u:FormItem NoLabel="True"> <u:FormItem NoLabel="True">
<Button HorizontalAlignment="Left" Content="No Label" /> <Button HorizontalAlignment="Left" Content="No Label" />
</u:FormItem> </u:FormItem>
</u:Form> </u:Form>
<StackPanel>
<TextBlock Text="{Binding Model.Name}" />
<TextBlock Text="{Binding Model.Email}" />
<TextBlock Text="{Binding Model.Date}" />
</StackPanel>
</StackPanel> </StackPanel>
</ScrollViewer>
</UserControl> </UserControl>

View File

@@ -22,12 +22,12 @@
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate TargetType="u:FormGroup"> <ControlTemplate TargetType="u:FormGroup">
<StackPanel> <StackPanel>
<ContentPresenter Content="{TemplateBinding Header}" FontWeight="Bold" /> <ContentPresenter Content="{TemplateBinding Header}" FontWeight="Bold" FontSize="18" />
<Rectangle <Rectangle
Height="1" Height="1"
Margin="0,8" Margin="0,8"
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
Fill="LightGray" /> Fill="{DynamicResource FormGroupBorderBrush}" />
<ItemsPresenter ItemsPanel="{TemplateBinding ItemsPanel}" /> <ItemsPresenter ItemsPanel="{TemplateBinding ItemsPanel}" />
</StackPanel> </StackPanel>
</ControlTemplate> </ControlTemplate>

View File

@@ -0,0 +1,5 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<!-- Add Resources Here -->
<SolidColorBrush x:Key="FormGroupBorderBrush" Color="White" Opacity="0.08"></SolidColorBrush>
</ResourceDictionary>

View File

@@ -7,6 +7,7 @@
<MergeResourceInclude Source="Dialog.axaml" /> <MergeResourceInclude Source="Dialog.axaml" />
<MergeResourceInclude Source="Divider.axaml" /> <MergeResourceInclude Source="Divider.axaml" />
<MergeResourceInclude Source="DualBadge.axaml" /> <MergeResourceInclude Source="DualBadge.axaml" />
<MergeResourceInclude Source="Form.axaml" />
<MergeResourceInclude Source="IPv4Box.axaml" /> <MergeResourceInclude Source="IPv4Box.axaml" />
<MergeResourceInclude Source="KeyGestureInput.axaml" /> <MergeResourceInclude Source="KeyGestureInput.axaml" />
<MergeResourceInclude Source="Loading.axaml" /> <MergeResourceInclude Source="Loading.axaml" />

View File

@@ -0,0 +1,5 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<!-- Add Resources Here -->
<SolidColorBrush x:Key="FormGroupBorderBrush" Color="#FF1C1F23" Opacity="0.08"></SolidColorBrush>
</ResourceDictionary>

View File

@@ -7,6 +7,7 @@
<MergeResourceInclude Source="Dialog.axaml" /> <MergeResourceInclude Source="Dialog.axaml" />
<MergeResourceInclude Source="Divider.axaml" /> <MergeResourceInclude Source="Divider.axaml" />
<MergeResourceInclude Source="DualBadge.axaml" /> <MergeResourceInclude Source="DualBadge.axaml" />
<MergeResourceInclude Source="Form.axaml" />
<MergeResourceInclude Source="IPv4Box.axaml" /> <MergeResourceInclude Source="IPv4Box.axaml" />
<MergeResourceInclude Source="KeyGestureInput.axaml" /> <MergeResourceInclude Source="KeyGestureInput.axaml" />
<MergeResourceInclude Source="Loading.axaml" /> <MergeResourceInclude Source="Loading.axaml" />

View File

@@ -70,6 +70,7 @@ public class Form: ItemsControl
Content = control, Content = control,
[!FormItem.LabelProperty] = control[!FormItem.LabelProperty], [!FormItem.LabelProperty] = control[!FormItem.LabelProperty],
[!FormItem.IsRequiredProperty] = control[!FormItem.IsRequiredProperty], [!FormItem.IsRequiredProperty] = control[!FormItem.IsRequiredProperty],
[!FormItem.NoLabelProperty] = control[!FormItem.NoLabelProperty],
}; };
} }
} }