feat: add a property to show if there is modal dialog available in a host.
This commit is contained in:
@@ -16,8 +16,16 @@
|
||||
<Design.DataContext>
|
||||
<vm:MainViewViewModel />
|
||||
</Design.DataContext>
|
||||
|
||||
<Grid ColumnDefinitions="Auto, *" RowDefinitions="Auto, *">
|
||||
<Panel>
|
||||
<Grid
|
||||
Classes.Blur="{Binding #host.HasModal}"
|
||||
ColumnDefinitions="Auto, *"
|
||||
RowDefinitions="Auto, *">
|
||||
<Grid.Styles>
|
||||
<Style Selector="Grid.Blur">
|
||||
<Setter Property="Effect" Value="blur(20)" />
|
||||
</Style>
|
||||
</Grid.Styles>
|
||||
<Border
|
||||
Grid.RowSpan="2"
|
||||
Padding="8,4"
|
||||
@@ -90,7 +98,7 @@
|
||||
<converters:ViewLocator />
|
||||
</ContentControl.ContentTemplate>
|
||||
</ContentControl>
|
||||
<u:OverlayDialogHost Grid.Row="0" Grid.Column="0" Grid.RowSpan="2" Grid.ColumnSpan="2" SnapThickness="20"/>
|
||||
</Grid>
|
||||
|
||||
<u:OverlayDialogHost Name="host" SnapThickness="20" />
|
||||
</Panel>
|
||||
</UserControl>
|
||||
|
||||
@@ -92,7 +92,7 @@ public partial class OverlayDialogHost
|
||||
Children.Add(mask);
|
||||
}
|
||||
this.Children.Add(control);
|
||||
_layers.Add(new DialogPair(mask, control));
|
||||
_layers.Add(new DialogPair(mask, control, false));
|
||||
control.Measure(this.Bounds.Size);
|
||||
control.Arrange(new Rect(control.DesiredSize));
|
||||
SetToPosition(control);
|
||||
@@ -118,6 +118,11 @@ public partial class OverlayDialogHost
|
||||
{
|
||||
await _maskDisappearAnimation.RunAsync(layer.Mask);
|
||||
Children.Remove(layer.Mask);
|
||||
if (layer.Modal)
|
||||
{
|
||||
_modalCount--;
|
||||
HasModal = _modalCount > 0;
|
||||
}
|
||||
}
|
||||
|
||||
ResetZIndices();
|
||||
@@ -142,6 +147,8 @@ public partial class OverlayDialogHost
|
||||
control.AddHandler(OverlayFeedbackElement.ClosedEvent, OnDialogControlClosing);
|
||||
control.AddHandler(DialogControlBase.LayerChangedEvent, OnDialogLayerChanged);
|
||||
_maskAppearAnimation.RunAsync(mask);
|
||||
_modalCount++;
|
||||
HasModal = _modalCount > 0;
|
||||
control.IsClosed = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,14 +24,29 @@ public partial class OverlayDialogHost: Canvas
|
||||
{
|
||||
internal PureRectangle? Mask;
|
||||
internal OverlayFeedbackElement Element;
|
||||
internal bool Modal;
|
||||
|
||||
public DialogPair(PureRectangle? mask, OverlayFeedbackElement element)
|
||||
public DialogPair(PureRectangle? mask, OverlayFeedbackElement element, bool modal = true)
|
||||
{
|
||||
Mask = mask;
|
||||
Element = element;
|
||||
Modal = modal;
|
||||
}
|
||||
}
|
||||
|
||||
private int _modalCount = 0;
|
||||
|
||||
|
||||
|
||||
public static readonly DirectProperty<OverlayDialogHost, bool> HasModalProperty = AvaloniaProperty.RegisterDirect<OverlayDialogHost, bool>(
|
||||
nameof(HasModal), o => o.HasModal);
|
||||
private bool _hasModal;
|
||||
public bool HasModal
|
||||
{
|
||||
get => _hasModal;
|
||||
private set => SetAndRaise(HasModalProperty, ref _hasModal, value);
|
||||
}
|
||||
|
||||
static OverlayDialogHost()
|
||||
{
|
||||
ClipToBoundsProperty.OverrideDefaultValue<OverlayDialogHost>(true);
|
||||
|
||||
Reference in New Issue
Block a user