Skip to content

Commit

Permalink
Merge pull request #81 from AvaloniaUtils/fixes-1
Browse files Browse the repository at this point in the history
Some fixes in demo
  • Loading branch information
SKProCH authored Jan 3, 2025
2 parents 89c5bfe + 4323ac4 commit a898cdf
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 38 deletions.
2 changes: 2 additions & 0 deletions DialogHost.Avalonia/DialogHost.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ namespace DialogHostAvalonia;
/// <summary>
/// A control that hosts dialog content in a modal overlay.
/// </summary>
[TemplatePart(ContentCoverName, typeof(Rectangle))]
[TemplatePart(DialogHostRoot, typeof(Panel))]
public class DialogHost : ContentControl {
/// <summary>
/// Gets the name for the content cover part in the control template.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace DialogHostDemo.Models;

public class Sample2Model {
public Sample2Model(int number) {
public class Sample3Model {
public Sample3Model(int number) {
Number = number;
}
public int Number { get; set; }
Expand Down
69 changes: 39 additions & 30 deletions DialogHost.Demo/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,48 @@
<Design.DataContext>
<vm:MainWindowViewModel />
</Design.DataContext>

<Window.DataTemplates>
<DataTemplate DataType="models:Sample3Model">
<StackPanel>
<TextBlock TextAlignment="Center">Your lucky number:</TextBlock>
<TextBlock Classes="Body1"
TextAlignment="Center"
Text="{Binding Number}" />
<Button Margin="0 8 0 0"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=dialogHostAvalonia:DialogHost}, Path=CloseDialogCommand}">
THANKS, CLOSE
</Button>
</StackPanel>
</DataTemplate>
</Window.DataTemplates>
<Window.Resources>
<StackPanel x:Key="Sample2View">
<TextBlock>It opened without animation</TextBlock>
<Button Margin="0 16 0 0"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=dialogHostAvalonia:DialogHost}, Path=CloseDialogCommand}">
CLOSE
</Button>
</StackPanel>
<StackPanel x:Key="Sample3View">
<ProgressBar Classes="Circle" IsIndeterminate="True" />
<Button Margin="0 16 0 0"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=dialogHostAvalonia:DialogHost}, Path=CloseDialogCommand}">
CLOSE
</Button>
</StackPanel>
<StackPanel x:Key="Sample4View">
<TextBlock>Everything blurred</TextBlock>
<Button Margin="0 16 0 0"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=dialogHostAvalonia:DialogHost}, Path=CloseDialogCommand}">
CLOSE
</Button>
</StackPanel>
</Window.Resources>

<dialogHostAvalonia:DialogHost Identifier="MainDialogHost"
DialogMargin="16"
dialogHostAvalonia:DialogHostStyle.CornerRadius="8">
<dialogHostAvalonia:DialogHost.DataTemplates>
<DataTemplate DataType="models:Sample2Model">
<StackPanel>
<TextBlock TextAlignment="Center">Your lucky number:</TextBlock>
<TextBlock Classes="Body1"
TextAlignment="Center"
Text="{Binding Number}" />
<Button Margin="0 8 0 0"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=dialogHostAvalonia:DialogHost}, Path=CloseDialogCommand}">
THANKS, CLOSE
</Button>
</StackPanel>
</DataTemplate>
</dialogHostAvalonia:DialogHost.DataTemplates>
<Grid Margin="8"
ColumnDefinitions="* 8 * 8 * 8 *" RowDefinitions="Auto 8 *"
VerticalAlignment="Center" HorizontalAlignment="Stretch">
Expand Down Expand Up @@ -94,20 +119,4 @@
</Border>
</Grid>
</dialogHostAvalonia:DialogHost>
<Window.Resources>
<StackPanel x:Key="Sample2View">
<TextBlock>It opened without animation</TextBlock>
<Button Margin="0 16 0 0"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=dialogHostAvalonia:DialogHost}, Path=CloseDialogCommand}">
CLOSE
</Button>
</StackPanel>
<StackPanel x:Key="Sample3View">
<ProgressBar Classes="Circle" IsIndeterminate="True" />
<Button Margin="0 16 0 0"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=dialogHostAvalonia:DialogHost}, Path=CloseDialogCommand}">
CLOSE
</Button>
</StackPanel>
</Window.Resources>
</Window>
12 changes: 6 additions & 6 deletions DialogHost.Demo/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ public MainWindow() {
private void InitializeComponent() {
AvaloniaXamlLoader.Load(this);
}

private async void OpenNoAnimationDialog(object? sender, RoutedEventArgs e) {
await DialogHost.Show(Resources["Sample2View"]!, "NoAnimationDialogHost");
}

private async void OpenDialogWithView(object? sender, RoutedEventArgs e) {
await DialogHost.Show(Resources["Sample3View"]!, "MainDialogHost");
}

private async void OpenDialogWithModel(object? sender, RoutedEventArgs e) {
await DialogHost.Show(new Sample2Model(new Random().Next(0, 100)), "MainDialogHost");
}

private async void OpenNoAnimationDialog(object? sender, RoutedEventArgs e) {
await DialogHost.Show(Resources["Sample2View"]!, "NoAnimationDialogHost");
await DialogHost.Show(new Sample3Model(new Random().Next(0, 100)), "MainDialogHost");
}

private async void OpenBlurDialog(object? sender, RoutedEventArgs e) {
await DialogHost.Show(Resources["Sample2View"]!, "BlurDialogHost");
await DialogHost.Show(Resources["Sample4View"]!, "BlurDialogHost");
}
}

0 comments on commit a898cdf

Please sign in to comment.