Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions samples/CommunityToolkit.Maui.Sample/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
</Style>
<Style x:Key="InheritancePopupStyle" TargetType="{x:Type popups:StyleInheritancePopup}" BasedOn="{StaticResource BasePopupStyle}">
<Setter Property="BackgroundColor" Value="SkyBlue" />
<Setter Property="Margin" Value="1" />
<Setter Property="Padding" Value="1" />
<Setter Property="HorizontalOptions" Value="Center" />
<Setter Property="VerticalOptions" Value="Center" />
</Style>

<Style x:Key="DynamicBasePopupStyle" TargetType="{x:Type popups:DynamicStyleInheritancePopup}">
Expand Down
37 changes: 12 additions & 25 deletions src/CommunityToolkit.Maui/Views/Popup/Popup.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,27 @@ namespace CommunityToolkit.Maui.Views;
/// </summary>
public partial class Popup : ContentView
{
/// <summary>
/// Bindable property to set the margin between the <see cref="Popup"/> and the edge of the window
/// </summary>
public static new readonly BindableProperty MarginProperty = View.MarginProperty;

/// <summary>
/// Bindable property to set the padding between the <see cref="Popup"/> border and the <see cref="Popup"/> content
/// </summary>
public static new readonly BindableProperty PaddingProperty = ContentView.PaddingProperty;

/// <summary>
/// Bindable property to set the horizontal position of the <see cref="Popup"/> when displayed on screen
/// </summary>
public static new readonly BindableProperty HorizontalOptionsProperty = View.HorizontalOptionsProperty;

/// <summary>
/// Bindable property to set the vertical position of the <see cref="Popup"/> when displayed on screen
/// </summary>
public static new readonly BindableProperty VerticalOptionsProperty = View.VerticalOptionsProperty;

/// <summary>
/// Backing BindableProperty for the <see cref="CanBeDismissedByTappingOutsideOfPopup"/> property.
/// </summary>
public static readonly BindableProperty CanBeDismissedByTappingOutsideOfPopupProperty = BindableProperty.Create(nameof(CanBeDismissedByTappingOutsideOfPopup), typeof(bool), typeof(Popup), PopupDefaults.CanBeDismissedByTappingOutsideOfPopup);

/// <summary>
/// Initializes Popup
/// </summary>
public Popup()
{
Margin = PopupDefaults.Margin;
Padding = PopupDefaults.Padding;
HorizontalOptions = PopupDefaults.HorizontalOptions;
VerticalOptions = PopupDefaults.VerticalOptions;
var style = new Style(typeof(Popup))
{
ApplyToDerivedTypes = true
};

style.Setters.Add(new Setter { Property = Popup.HorizontalOptionsProperty, Value = PopupDefaults.HorizontalOptions });
style.Setters.Add(new Setter { Property = Popup.VerticalOptionsProperty, Value = PopupDefaults.VerticalOptions });
style.Setters.Add(new Setter { Property = Popup.MarginProperty, Value = PopupDefaults.Margin });
style.Setters.Add(new Setter { Property = Popup.PaddingProperty, Value = PopupDefaults.Padding });

Resources.Add(style);
}

/// <summary>
Expand Down
9 changes: 5 additions & 4 deletions src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.Maui.Controls.PlatformConfiguration;
using Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;
using Microsoft.Maui.Controls.Shapes;
using static Microsoft.Maui.Controls.View;

namespace CommunityToolkit.Maui.Views;

Expand Down Expand Up @@ -136,13 +137,13 @@ protected override void OnNavigatedTo(NavigatedToEventArgs args)
popup.SetBinding(BackgroundProperty, static (View view) => view.Background, source: view, mode: BindingMode.OneWay);
popup.SetBinding(BindingContextProperty, static (View view) => view.BindingContext, source: view, mode: BindingMode.OneWay);
popup.SetBinding(BackgroundColorProperty, static (View view) => view.BackgroundColor, source: view, mode: BindingMode.OneWay);
popup.SetBinding(Popup.MarginProperty, static (View view) => view.Margin, source: view, mode: BindingMode.OneWay);
popup.SetBinding(Popup.VerticalOptionsProperty, static (View view) => view.VerticalOptions, source: view, mode: BindingMode.OneWay, converter: new VerticalOptionsConverter());
popup.SetBinding(Popup.HorizontalOptionsProperty, static (View view) => view.HorizontalOptions, source: view, mode: BindingMode.OneWay, converter: new HorizontalOptionsConverter());
popup.SetBinding(MarginProperty, static (View view) => view.Margin, source: view, mode: BindingMode.OneWay);
popup.SetBinding(VerticalOptionsProperty, static (View view) => view.VerticalOptions, source: view, mode: BindingMode.OneWay, converter: new VerticalOptionsConverter());
popup.SetBinding(HorizontalOptionsProperty, static (View view) => view.HorizontalOptions, source: view, mode: BindingMode.OneWay, converter: new HorizontalOptionsConverter());

if (view is IPaddingElement paddingElement)
{
popup.SetBinding(Popup.PaddingProperty, static (IPaddingElement paddingElement) => paddingElement.Padding, source: paddingElement, mode: BindingMode.OneWay, converter: new PaddingConverter());
popup.SetBinding(PaddingProperty, static (IPaddingElement paddingElement) => paddingElement.Padding, source: paddingElement, mode: BindingMode.OneWay, converter: new PaddingConverter());
}

return popup;
Expand Down
Loading