feat: add default template, add sample.
This commit is contained in:
@@ -13,5 +13,6 @@
|
||||
<StackPanel HorizontalAlignment="Left" >
|
||||
<u:EnumSelector EnumType="{x:Type common:Position}" Value="{Binding SelectedPosition}"></u:EnumSelector>
|
||||
<Button Content="Call Drawer" HorizontalAlignment="Stretch" Command="{Binding OpenDrawerCommand}"></Button>
|
||||
<Button Content="Default Drawer" Command="{Binding OpenDefaultDrawerCommand}"></Button>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace Ursa.Demo.ViewModels;
|
||||
public partial class DrawerDemoViewModel: ObservableObject
|
||||
{
|
||||
public ICommand OpenDrawerCommand { get; set; }
|
||||
public ICommand OpenDefaultDrawerCommand { get; set; }
|
||||
|
||||
[ObservableProperty] private Position _selectedPosition;
|
||||
|
||||
@@ -20,6 +21,19 @@ public partial class DrawerDemoViewModel: ObservableObject
|
||||
public DrawerDemoViewModel()
|
||||
{
|
||||
OpenDrawerCommand = new AsyncRelayCommand(OpenDrawer);
|
||||
OpenDefaultDrawerCommand = new AsyncRelayCommand(OpenDefaultDrawer);
|
||||
SelectedPosition = Position.Right;
|
||||
}
|
||||
|
||||
private Task OpenDefaultDrawer()
|
||||
{
|
||||
return Drawer.Show<PlainDialog, PlainDialogViewModel, bool>(new PlainDialogViewModel(), new DefaultDrawerOptions()
|
||||
{
|
||||
Buttons = DialogButton.OKCancel,
|
||||
Position = SelectedPosition,
|
||||
Title = "Please select a date",
|
||||
CanClickOnMaskToClose = false,
|
||||
});
|
||||
}
|
||||
|
||||
private async Task OpenDrawer()
|
||||
|
||||
@@ -63,4 +63,105 @@
|
||||
<Setter Property="BorderThickness" Value="0 1 0 0" />
|
||||
</Style>
|
||||
</ControlTheme>
|
||||
|
||||
<ControlTheme x:Key="{x:Type u:DefaultDrawerControl}" TargetType="u:DefaultDrawerControl">
|
||||
<Setter Property="VerticalAlignment" Value="Stretch"></Setter>
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch"></Setter>
|
||||
<Setter Property="Template">
|
||||
<ControlTemplate TargetType="u:DefaultDrawerControl">
|
||||
<Border Name="PART_Root"
|
||||
Margin="8 -1 -1 -1"
|
||||
Padding="0"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
Classes="Shadow"
|
||||
ClipToBounds="False"
|
||||
CornerRadius="12 0 0 12"
|
||||
BorderThickness="1 0 0 0"
|
||||
IsHitTestVisible="True"
|
||||
Theme="{DynamicResource CardBorder}">
|
||||
<Border ClipToBounds="True" CornerRadius="{TemplateBinding CornerRadius}">
|
||||
<Grid RowDefinitions="Auto, *, Auto">
|
||||
<ScrollViewer Grid.Row="1">
|
||||
<ContentPresenter
|
||||
Name="PART_ContentPresenter"
|
||||
Grid.Row="1"
|
||||
Margin="24,8"
|
||||
Content="{TemplateBinding Content}" />
|
||||
</ScrollViewer>
|
||||
<Grid Grid.Row="0" ColumnDefinitions=" *, Auto">
|
||||
<TextBlock
|
||||
Name="PART_Title"
|
||||
Grid.Column="0"
|
||||
Margin="24,24,0,0"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="16"
|
||||
FontWeight="Bold"
|
||||
IsHitTestVisible="False"
|
||||
IsVisible="{TemplateBinding Title,
|
||||
Converter={x:Static ObjectConverters.IsNotNull}}"
|
||||
Text="{TemplateBinding Title}"
|
||||
TextWrapping="Wrap" />
|
||||
<Button
|
||||
Name="{x:Static u:DrawerControlBase.PART_CloseButton}"
|
||||
Grid.Column="1"
|
||||
Margin="0,24,24,0"
|
||||
DockPanel.Dock="Right"
|
||||
Theme="{DynamicResource CloseButton}" />
|
||||
</Grid>
|
||||
<StackPanel
|
||||
Grid.Row="2"
|
||||
Margin="24,0,24,24"
|
||||
HorizontalAlignment="Right"
|
||||
Orientation="Horizontal">
|
||||
<Button
|
||||
Name="{x:Static u:DefaultDialogControl.PART_CancelButton}"
|
||||
Margin="8,0,0,0"
|
||||
Classes="Tertiary"
|
||||
Content="{DynamicResource STRING_MENU_DIALOG_CANCEL}" />
|
||||
<Button
|
||||
Name="{x:Static u:DefaultDialogControl.PART_NoButton}"
|
||||
Margin="8,0,0,0"
|
||||
Classes="Danger"
|
||||
Content="{DynamicResource STRING_MENU_DIALOG_NO}"
|
||||
Theme="{DynamicResource SolidButton}" />
|
||||
<Button
|
||||
Name="{x:Static u:DefaultDialogControl.PART_YesButton}"
|
||||
Margin="8,0,0,0"
|
||||
Classes="Primary"
|
||||
Content="{DynamicResource STRING_MENU_DIALOG_YES}"
|
||||
Theme="{DynamicResource SolidButton}" />
|
||||
<Button
|
||||
Name="{x:Static u:DefaultDialogControl.PART_OKButton}"
|
||||
Margin="8,0,0,0"
|
||||
Classes="Primary"
|
||||
Content="{DynamicResource STRING_MENU_DIALOG_OK}"
|
||||
Theme="{DynamicResource SolidButton}" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter>
|
||||
<Style Selector="^[Position=Right] /template/ Border#PART_Root">
|
||||
<Setter Property="Margin" Value="8 0 0 0" />
|
||||
<Setter Property="CornerRadius" Value="12 0 0 12" />
|
||||
<Setter Property="BorderThickness" Value="1 0 0 0" />
|
||||
</Style>
|
||||
<Style Selector="^[Position=Left] /template/ Border#PART_Root">
|
||||
<Setter Property="Margin" Value="0 0 8 0" />
|
||||
<Setter Property="CornerRadius" Value="0 12 12 0" />
|
||||
<Setter Property="BorderThickness" Value="0 0 1 0" />
|
||||
</Style>
|
||||
<Style Selector="^[Position=Top] /template/ Border#PART_Root">
|
||||
<Setter Property="Margin" Value="0 0 0 8" />
|
||||
<Setter Property="CornerRadius" Value="0 0 12 12" />
|
||||
<Setter Property="BorderThickness" Value="0 0 0 1" />
|
||||
</Style>
|
||||
<Style Selector="^[Position=Bottom] /template/ Border#PART_Root">
|
||||
<Setter Property="Margin" Value="0 8 0 0" />
|
||||
<Setter Property="CornerRadius" Value="12 12 0 0" />
|
||||
<Setter Property="BorderThickness" Value="0 1 0 0" />
|
||||
</Style>
|
||||
</ControlTheme>
|
||||
</ResourceDictionary>
|
||||
|
||||
@@ -59,9 +59,68 @@ public class DefaultDrawerControl: DrawerControlBase
|
||||
_okButton = e.NameScope.Find<Button>(PART_OKButton);
|
||||
_cancelButton = e.NameScope.Find<Button>(PART_CancelButton);
|
||||
EventHelper.RegisterClickEvent(OnDefaultButtonClick, _yesButton, _noButton, _okButton, _cancelButton);
|
||||
SetButtonVisibility();
|
||||
}
|
||||
|
||||
private void SetButtonVisibility()
|
||||
{
|
||||
bool isCloseButtonVisible = DataContext is IDialogContext || Buttons != DialogButton.YesNo;
|
||||
SetVisibility(_closeButton, isCloseButtonVisible);
|
||||
switch (Buttons)
|
||||
{
|
||||
case DialogButton.None:
|
||||
SetVisibility(_okButton, false);
|
||||
SetVisibility(_cancelButton, false);
|
||||
SetVisibility(_yesButton, false);
|
||||
SetVisibility(_noButton, false);
|
||||
break;
|
||||
case DialogButton.OK:
|
||||
SetVisibility(_okButton, true);
|
||||
SetVisibility(_cancelButton, false);
|
||||
SetVisibility(_yesButton, false);
|
||||
SetVisibility(_noButton, false);
|
||||
break;
|
||||
case DialogButton.OKCancel:
|
||||
SetVisibility(_okButton, true);
|
||||
SetVisibility(_cancelButton, true);
|
||||
SetVisibility(_yesButton, false);
|
||||
SetVisibility(_noButton, false);
|
||||
break;
|
||||
case DialogButton.YesNo:
|
||||
SetVisibility(_okButton, false);
|
||||
SetVisibility(_cancelButton, false);
|
||||
SetVisibility(_yesButton, true);
|
||||
SetVisibility(_noButton, true);
|
||||
break;
|
||||
case DialogButton.YesNoCancel:
|
||||
SetVisibility(_okButton, false);
|
||||
SetVisibility(_cancelButton, true);
|
||||
SetVisibility(_yesButton, true);
|
||||
SetVisibility(_noButton, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDefaultButtonClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is Button button)
|
||||
{
|
||||
if (button == _okButton)
|
||||
{
|
||||
OnElementClosing(this, DialogResult.OK);
|
||||
}
|
||||
else if (button == _cancelButton)
|
||||
{
|
||||
OnElementClosing(this, DialogResult.Cancel);
|
||||
}
|
||||
else if (button == _yesButton)
|
||||
{
|
||||
OnElementClosing(this, DialogResult.Yes);
|
||||
}
|
||||
else if (button == _noButton)
|
||||
{
|
||||
OnElementClosing(this, DialogResult.No);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user