Skip to content

Commit

Permalink
Merge branch 'absolute' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Platonenkov committed Nov 30, 2021
2 parents 1dfd087 + 33c6f5d commit 954c89a
Show file tree
Hide file tree
Showing 17 changed files with 1,067 additions and 242 deletions.
19 changes: 18 additions & 1 deletion Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,24 @@ Will work when will start new message stack.
//If messages count in overlay window will be more that maximum - progress bar will start collapsed (progress bar never closing automatically)
NotificationConstants.CollapseProgressIfMoreRows = true;
```


- For `Absolute` message position:
Set Message position as `Absolute`, and set `NotificationConstants.AbsolutePosition`

but, You must set base corner for position margin.

Sample:
```
NotificationConstants.AbsolutePosition.X = 50D;
NotificationConstants.AbsolutePosition.Y = 100D;
NotificationConstants.AbsolutePosition.BaseCorner= Corner.TopRight;
```

- Reverse message stack
Decide what message will be from above
Use `NotificationConstants.IsReversedPanel` to change stack orientation. Set as `null to default`.


</details>
<details>
<br />
Expand Down
11 changes: 6 additions & 5 deletions Notification.Wpf/Base/NotificationsOverlayWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
ShowActivated="False"
WindowStartupLocation ="CenterScreen"
d:DesignWidth="900"
d:DesignHeight="600">
<controls1:NotificationArea Position="{Binding MessagePosition,RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
CollapseProgressAuto="{Binding CollapseProgressAutoIfMoreMessages, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
MaxItems="{Binding MaxWindowItems, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
Margin="8"/>
d:DesignHeight="600"
>
<controls1:NotificationArea Position="{Binding MessagePosition,RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
CollapseProgressAuto="{Binding CollapseProgressAutoIfMoreMessages, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
MaxItems="{Binding MaxWindowItems, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
Margin="8"/>
</Window>
50 changes: 50 additions & 0 deletions Notification.Wpf/Classes/AbsolutePosition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace Notification.Wpf.Classes
{
/// <summary> Are absolute position </summary>
public class AbsolutePosition
{
/// <summary> X position </summary>
public double X { get; set; }
/// <summary> Y position </summary>
public double Y { get; set; }

/// <summary> Base corner </summary>
public Corner BaseCorner { get; set; }

/// <summary> position </summary>
public Thickness Margin => BaseCorner switch
{
Corner.TopLeft => new Thickness(X, Y, 0, 0),
Corner.TopRight => new Thickness(0, Y, X, 0),
Corner.BottomLeft => new Thickness(X, 0, 0, Y),
Corner.BottomRight => new Thickness(0, 0, X, Y),
_ => throw new ArgumentOutOfRangeException()
};
/// <summary> Horizontal Alignment </summary>
public HorizontalAlignment HorAlign => BaseCorner switch
{
Corner.TopLeft => HorizontalAlignment.Left,
Corner.TopRight => HorizontalAlignment.Right,
Corner.BottomLeft => HorizontalAlignment.Left,
Corner.BottomRight => HorizontalAlignment.Right,
_ => throw new ArgumentOutOfRangeException()
};
/// <summary> Horizontal Alignment </summary>
public VerticalAlignment VertAlign => BaseCorner switch
{
Corner.TopLeft => VerticalAlignment.Top,
Corner.TopRight => VerticalAlignment.Top,
Corner.BottomLeft => VerticalAlignment.Bottom,
Corner.BottomRight => VerticalAlignment.Bottom,
_ => throw new ArgumentOutOfRangeException()
};

}
}
10 changes: 10 additions & 0 deletions Notification.Wpf/Classes/Enums/Corner.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Notification.Wpf;

/// <summary> corners in window </summary>
public enum Corner
{
TopLeft,
TopRight,
BottomLeft,
BottomRight
}
13 changes: 13 additions & 0 deletions Notification.Wpf/Constants/NotificationConstants.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Windows;
using System.Windows.Media;
using Notification.Wpf.Base;
using Notification.Wpf.Classes;
using Notification.Wpf.Controls;

// ReSharper disable FieldCanBeMadeReadOnly.Global
Expand All @@ -18,6 +19,12 @@ public class NotificationConstants
/// <summary> Overlay message position </summary>
public static NotificationPosition MessagePosition { get; set; } = NotificationPosition.BottomRight;

/// <summary> Reverse are when absolute </summary>
public static bool? IsReversedPanel { get; set; }

/// <summary> Default message position when position absolute </summary>
public static AbsolutePosition AbsolutePosition { get; } = new AbsolutePosition();

#region Notification

#region Default colors
Expand Down Expand Up @@ -154,5 +161,11 @@ public class NotificationConstants
public static object DefaultProgressButtonContent { get; set; } = "Cancel";

#endregion

/// <summary> work area height </summary>
public static double AreaHeight => SystemParameters.WorkArea.Height;
/// <summary> work area width </summary>
public static double AreaWidth => SystemParameters.WorkArea.Width;

}
}
47 changes: 43 additions & 4 deletions Notification.Wpf/Controls/NotificationArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

using Notification.Wpf.Constants;
using Notification.Wpf.View;

using Notifications.Wpf.ViewModels;

namespace Notification.Wpf.Controls
Expand All @@ -27,16 +30,34 @@ public class NotificationArea : Control

#endregion

//public NotificationPosition Position
//{
// get => (NotificationPosition)GetValue(PositionProperty);
// set => SetValue(PositionProperty, value);
//}

//// Using a DependencyProperty as the backing store for Position. This enables animation, styling, binding, etc...
//public static readonly DependencyProperty PositionProperty =
// DependencyProperty.Register("Position", typeof(NotificationPosition), typeof(NotificationArea), new PropertyMetadata(NotificationPosition.BottomRight));

#region Position : NotificationPosition - Area position on overlay window

/// <summary>Area position on overlay window</summary>
public static readonly DependencyProperty PositionProperty =
DependencyProperty.Register(
nameof(Position),
typeof(NotificationPosition),
typeof(NotificationArea),
new PropertyMetadata(NotificationPosition.BottomRight));

/// <summary>Area position on overlay window</summary>
public NotificationPosition Position
{
get => (NotificationPosition)GetValue(PositionProperty);
set => SetValue(PositionProperty, value);
}

// Using a DependencyProperty as the backing store for Position. This enables animation, styling, binding, etc...
public static readonly DependencyProperty PositionProperty =
DependencyProperty.Register("Position", typeof(NotificationPosition), typeof(NotificationArea), new PropertyMetadata(NotificationPosition.BottomRight));

#endregion

public int MaxItems
{
Expand All @@ -47,6 +68,21 @@ public int MaxItems
public static readonly DependencyProperty MaxItemsProperty =
DependencyProperty.Register("MaxItems", typeof(int), typeof(NotificationArea), new PropertyMetadata(int.MaxValue));

#region IsReversed : bool - Are is reversed

/// <summary>Are is reversed</summary>
public static readonly DependencyProperty IsReversedProperty =
DependencyProperty.Register(
nameof(IsReversed),
typeof(bool),
typeof(NotificationArea),
new PropertyMetadata(default(bool)));

/// <summary>Are is reversed</summary>
public bool IsReversed { get => (bool)GetValue(IsReversedProperty); set => SetValue(IsReversedProperty, value); }

#endregion

private IList _items;

public NotificationArea()
Expand All @@ -65,6 +101,9 @@ public override void OnApplyTemplate()
base.OnApplyTemplate();
var itemsControl = GetTemplateChild("PART_Items") as Panel;
_items = itemsControl?.Children;

IsReversed = NotificationConstants.IsReversedPanel is { } reverse ? reverse
: Position is NotificationPosition.BottomCenter or NotificationPosition.BottomLeft or NotificationPosition.BottomRight;
}

#if NET40
Expand Down
3 changes: 2 additions & 1 deletion Notification.Wpf/Controls/NotificationPosition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public enum NotificationPosition
BottomCenter,
CenterLeft,
CenterRight,
Center
Center,
Absolute
}
}
Loading

0 comments on commit 954c89a

Please sign in to comment.