Skip to content

Commit

Permalink
Merge pull request #345 from af-silva/master
Browse files Browse the repository at this point in the history
Fix Custom Dialog Dockpanel still using space even if its children are set to invisible
  • Loading branch information
SKProCH authored Jan 29, 2024
2 parents bd9d8ba + 468a890 commit b53cf89
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
7 changes: 6 additions & 1 deletion Material.Avalonia.Dialogs/Styles/EmbeddedDialogControl.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@
Content="{CompiledBinding DialogIcon}"
ContentTemplate="{StaticResource DialogHeaderIconTemplate}"
IsVisible="{CompiledBinding !!DialogIcon}" />

<DockPanel.IsVisible>
<MultiBinding Converter="{x:Static BoolConverters.Or}">
<CompiledBinding Converter="{x:Static ObjectConverters.IsNotNull}" Path="DialogIcon" />
<CompiledBinding Converter="{x:Static StringConverters.IsNotNullOrEmpty}" Path="ContentHeader" />
</MultiBinding>
</DockPanel.IsVisible>
<TextBlock Name="{x:Static naming:PartNames.PartHeaderText}"
Classes="Headline6"
IsVisible="{CompiledBinding !!ContentHeader.Length}"
Expand Down
14 changes: 14 additions & 0 deletions Material.Demo/Pages/CustomDialogContentDemo.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<UserControl x:Class="Material.Demo.Pages.CustomDialogContentDemo"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">
<Grid Margin="5"
Background="LightGray"
RowDefinitions="Auto,*">
<TextBox Text="This should use all the available space!" />
</Grid>
</UserControl>
11 changes: 11 additions & 0 deletions Material.Demo/Pages/CustomDialogContentDemo.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;

namespace Material.Demo.Pages;

public partial class CustomDialogContentDemo : UserControl {
public CustomDialogContentDemo() {
InitializeComponent();
}
}
21 changes: 20 additions & 1 deletion Material.Demo/ViewModels/DialogDemoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Media.Imaging;
using Avalonia.Platform;
using Material.Demo.Pages;
using Material.Dialog;
using Material.Dialog.Enums;
using Material.Dialog.Icons;
Expand All @@ -31,7 +32,8 @@ public DialogDemoViewModel() {
new DialogDemoItemViewModel("Login dialog", LoginDialog),
new DialogDemoItemViewModel("Folder rename dialog", FolderNameDialog),
new DialogDemoItemViewModel("Time picker", TimePickerDialog),
new DialogDemoItemViewModel("Date picker", DatePickerDialog)
new DialogDemoItemViewModel("Date picker", DatePickerDialog),
new DialogDemoItemViewModel("Custom dialog", CustomDialog),
};
}

Expand Down Expand Up @@ -267,5 +269,22 @@ private async IAsyncEnumerable<string> DatePickerDialog() {
yield return $"TimeSpan: {r.ToString("d")}";
_previousDatePickerResult = r;
}

private async IAsyncEnumerable<string> CustomDialog() {
// Open asset stream using assets.Open method.
await using var icon = AssetLoader.Open(new Uri("avares://Material.Demo/Assets/avalonia-logo.png"));

var dialog = DialogHelper.CreateCustomDialog(new CustomDialogBuilderParams()
{
Content = new CustomDialogContentDemo(),
StartupLocation = WindowStartupLocation.CenterOwner,
Borderless = false,
});

var result = await dialog.ShowDialog(_window);

yield return $"Result: {result.GetResult}";
}

}
}

0 comments on commit b53cf89

Please sign in to comment.