Skip to content

Commit

Permalink
Merge pull request #22 from Enterwell/amkuchta-GH17-18_AdditionalCont…
Browse files Browse the repository at this point in the history
…entArea

Amkuchta gh17 18 additional content area
  • Loading branch information
AleksandarDev authored Jun 9, 2018
2 parents 5aa7e47 + 27046b2 commit 0ac533d
Show file tree
Hide file tree
Showing 18 changed files with 294 additions and 287 deletions.
10 changes: 10 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.4.0] - 2018-06-09
### Added
- Added `WithAdditionalContent` feature

### Changed
- `NotificationHeaderTextStyle` and `NotificationMessageTextStyle` are now aligned left horizontally (instead of stretched)

### Fixed
- `INotificationAnimation` interface is now marked as public

## [1.3.1] - 2018-05-30
### Fixed
- Fixed message header foreground not set by `SetForeground` method call.
Expand Down
12 changes: 2 additions & 10 deletions Enterwell.Clients.Wpf.Notifications.Sample/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

namespace Enterwell.Clients.Wpf.Notifications.Sample
namespace Enterwell.Clients.Wpf.Notifications.Sample
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
public partial class App
{
}
}
18 changes: 10 additions & 8 deletions Enterwell.Clients.Wpf.Notifications.Sample/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<controls1:MetroWindow
<mahapps:MetroWindow
x:Class="Enterwell.Clients.Wpf.Notifications.Sample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:Enterwell.Clients.Wpf.Notifications.Controls;assembly=Enterwell.Clients.Wpf.Notifications"
xmlns:controls1="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mahapps="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="MainWindow"
Width="900"
Expand All @@ -16,13 +16,16 @@
WindowStartupLocation="CenterScreen"
WindowTransitionsEnabled="False"
mc:Ignorable="d">
<controls1:MetroWindow.Resources>
<mahapps:MetroWindow.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Enterwell.Clients.Wpf.Notifications;component/Themes/Generic.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</controls1:MetroWindow.Resources>
</mahapps:MetroWindow.Resources>
<mahapps:MetroWindow.WindowButtonCommands>
<mahapps:WindowButtonCommands Style="{DynamicResource MahApps.Metro.Styles.WindowButtonCommands.Win10}" />
</mahapps:MetroWindow.WindowButtonCommands>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
Expand All @@ -38,7 +41,7 @@
<controls:NotificationMessageContainer Manager="{Binding Manager}" />
</Border>

<StackPanel
<WrapPanel
Grid.Row="1"
Grid.Column="0"
Grid.ColumnSpan="3"
Expand Down Expand Up @@ -95,7 +98,6 @@
Content="Additional Content Areas"
Style="{StaticResource NotificationMessageButtonStyle}" />

</StackPanel>
</WrapPanel>
</Grid>
</controls1:MetroWindow>

</mahapps:MetroWindow>
23 changes: 2 additions & 21 deletions Enterwell.Clients.Wpf.Notifications.Sample/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using System;
using System.Collections.ObjectModel;
using System.Runtime.Serialization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Enterwell.Clients.Wpf.Notifications.Controls;

namespace Enterwell.Clients.Wpf.Notifications.Sample
{
Expand Down Expand Up @@ -92,16 +89,11 @@ private void ButtonBaseInfoDelayOnClick(object sender, RoutedEventArgs e)

private void ButtonBaseAdditionalContentOnClick(object sender, RoutedEventArgs e)
{
Thickness margin = new Thickness();
margin.Top = margin.Bottom = margin.Left = margin.Right = 5;
this.Manager
.CreateMessage()
.Accent("#1751C3")
.Animates(true)
.AnimationInDuration(0.5)
.AnimationOutDuration(0.5)
.Background("#333")
.Foreground("#000")
.Foreground("#333")
.HasBadge("Info")
.HasHeader("Header")
.HasMessage("This is the message!")
Expand Down Expand Up @@ -140,23 +132,12 @@ private void ButtonBaseAdditionalContentOnClick(object sender, RoutedEventArgs e
HorizontalAlignment = HorizontalAlignment.Stretch,
Background = Brushes.Orange
})
.WithAdditionalContent(ContentLocation.OverBadge, new Border
.WithAdditionalContent(ContentLocation.AboveBadge, new Border
{
Height = 40,
Width = 40,
Background = Brushes.Indigo
})
.WithOverlay(new ProgressBar
{
VerticalAlignment = VerticalAlignment.Bottom,
HorizontalAlignment = HorizontalAlignment.Stretch,
Height = 3,
BorderThickness = new Thickness(0),
Foreground = new SolidColorBrush(Color.FromArgb(128, 255, 255, 255)),
Background = Brushes.Transparent,
IsIndeterminate = true,
IsHitTestVisible = false
})
.Dismiss().WithButton("Dismiss", button => { })
.Queue();
}
Expand Down
27 changes: 0 additions & 27 deletions Enterwell.Clients.Wpf.Notifications/ActionExtensions.cs

This file was deleted.

13 changes: 5 additions & 8 deletions Enterwell.Clients.Wpf.Notifications/ContentLocation.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Enterwell.Clients.Wpf.Notifications
namespace Enterwell.Clients.Wpf.Notifications
{
/// <summary>
/// The additional content location.
/// </summary>
public enum ContentLocation
{
Top,
Bottom,
Left,
Right,
Main,
OverBadge
AboveBadge
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,7 @@ public double AnimationOutDuration
/// <summary>
/// The animatable element used for show/hide animations.
/// </summary>
public UIElement AnimatableElement
{
get => this;
}
public UIElement AnimatableElement => this;

/// <summary>
/// The animation in.
Expand Down Expand Up @@ -327,7 +324,7 @@ public DependencyProperty AnimationInDependencyProperty
get
{
var property = (DependencyProperty)GetValue(AnimationInDependencyPropProperty);
return property ?? UIElement.OpacityProperty;
return property ?? OpacityProperty;
}
set => SetValue(AnimationInDependencyPropProperty, value);
}
Expand All @@ -340,7 +337,7 @@ public DependencyProperty AnimationOutDependencyProperty
get
{
var property = (DependencyProperty)GetValue(AnimationOutDependencyPropProperty);
return property ?? UIElement.OpacityProperty;
return property ?? OpacityProperty;
}
set => SetValue(AnimationOutDependencyPropProperty, value);
}
Expand Down Expand Up @@ -376,7 +373,7 @@ public DependencyProperty AnimationOutDependencyProperty
DependencyProperty.Register("AdditionalContentRight", typeof(object), typeof(NotificationMessage), new PropertyMetadata(null));

/// <summary>
/// The additional content center property.
/// The additional content main property.
/// </summary>
public static readonly DependencyProperty AdditionalContentMainProperty =
DependencyProperty.Register("AdditionalContentMain", typeof(object), typeof(NotificationMessage), new PropertyMetadata(null));
Expand All @@ -400,8 +397,7 @@ public DependencyProperty AnimationOutDependencyProperty
/// <param name="dependencyPropertyChangedEventArgs">The <see cref="DependencyPropertyChangedEventArgs" /> instance containing the event data.</param>
private static void AccentBrushPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
{
var @this = dependencyObject as NotificationMessage;
if (@this == null)
if (!(dependencyObject is NotificationMessage @this))
throw new NullReferenceException("Dependency object is not of valid type " + nameof(NotificationMessage));

if (@this.BadgeAccentBrush == null)
Expand Down Expand Up @@ -446,8 +442,7 @@ private static void AccentBrushPropertyChangedCallback(DependencyObject dependen
/// <param name="dependencyPropertyChangedEventArgs">The <see cref="DependencyPropertyChangedEventArgs" /> instance containing the event data.</param>
private static void BadgeTextPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
{
var @this = dependencyObject as NotificationMessage;
if (@this == null)
if (!(dependencyObject is NotificationMessage @this))
throw new NullReferenceException("Dependency object is not of valid type " + nameof(NotificationMessage));

@this.BadgeVisibility = dependencyPropertyChangedEventArgs.NewValue == null
Expand All @@ -474,8 +469,7 @@ private static void BadgeTextPropertyChangedCallback(DependencyObject dependency
/// <param name="dependencyPropertyChangedEventArgs">The <see cref="DependencyPropertyChangedEventArgs" /> instance containing the event data.</param>
private static void HeaderPropertyChangesCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
{
var @this = dependencyObject as NotificationMessage;
if (@this == null)
if (!(dependencyObject is NotificationMessage @this))
throw new NullReferenceException("Dependency object is not of valid type " + nameof(NotificationMessage));

@this.HeaderVisibility = dependencyPropertyChangedEventArgs.NewValue == null
Expand All @@ -502,8 +496,7 @@ private static void HeaderPropertyChangesCallback(DependencyObject dependencyObj
/// <param name="dependencyPropertyChangedEventArgs">The <see cref="DependencyPropertyChangedEventArgs" /> instance containing the event data.</param>
private static void MessagePropertyChangesCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
{
var @this = dependencyObject as NotificationMessage;
if (@this == null)
if (!(dependencyObject is NotificationMessage @this))
throw new NullReferenceException("Dependency object is not of valid type " + nameof(NotificationMessage));

@this.MessageVisibility = dependencyPropertyChangedEventArgs.NewValue == null
Expand Down Expand Up @@ -576,7 +569,7 @@ public NotificationMessage()
{
this.Buttons = new ObservableCollection<object>();

//Setting the default text color, if not defined by user.
// Setting the default text color, if not defined by user.
this.Foreground = new BrushConverter().ConvertFromString("#DDDDDD") as Brush;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Animation;

namespace Enterwell.Clients.Wpf.Notifications.Controls
{
Expand All @@ -19,8 +18,8 @@ public class NotificationMessageContainer : ItemsControl
/// </value>
public INotificationMessageManager Manager
{
get { return (INotificationMessageManager)GetValue(ManagerProperty); }
set { SetValue(ManagerProperty, value); }
get => (INotificationMessageManager)this.GetValue(ManagerProperty);
set => this.SetValue(ManagerProperty, value);
}

/// <summary>
Expand All @@ -34,11 +33,10 @@ public INotificationMessageManager Manager
/// </summary>
/// <param name="dependencyObject">The dependency object.</param>
/// <param name="dependencyPropertyChangedEventArgs">The <see cref="DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
/// <exception cref="NullReferenceException">Dependency object is not of valid type " + nameof(NotificationMessageContainer)</exception>
/// <exception cref="NullReferenceException">Dependency object is not of valid type - expected NotificationMessageContainer.</exception>
private static void ManagerPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
{
var @this = dependencyObject as NotificationMessageContainer;
if (@this == null)
if (!(dependencyObject is NotificationMessageContainer @this))
throw new NullReferenceException("Dependency object is not of valid type " + nameof(NotificationMessageContainer));

if (dependencyPropertyChangedEventArgs.OldValue is INotificationMessageManager oldManager)
Expand Down Expand Up @@ -80,12 +78,13 @@ private void ManagerOnOnMessageDismissed(object sender, NotificationMessageManag
throw new InvalidOperationException(
"Can't use both ItemsSource and Items collection at the same time.");

if (args.Message is INotificationAnimation)
if (args.Message is INotificationAnimation animatableMessage)
{
var animatableMessage = args.Message as INotificationAnimation;
var animation = animatableMessage.AnimationOut;
if (animatableMessage.Animates && animatableMessage.AnimatableElement != null
&& animation != null && animatableMessage.AnimationOutDependencyProperty != null)
if (animation != null &&
animatableMessage.Animates &&
animatableMessage.AnimatableElement != null &&
animatableMessage.AnimationOutDependencyProperty != null)
{
animation.Completed += (s, a) => this.RemoveMessage(args.Message);
animatableMessage.AnimatableElement.BeginAnimation(animatableMessage.AnimationOutDependencyProperty, animation);
Expand All @@ -103,7 +102,7 @@ private void ManagerOnOnMessageDismissed(object sender, NotificationMessageManag

private void RemoveMessage(INotificationMessage message)
{
this.Items?.Remove(message);
this.Items.Remove(message);
}

/// <summary>
Expand All @@ -118,11 +117,10 @@ private void ManagerOnOnMessageQueued(object sender, NotificationMessageManagerE
throw new InvalidOperationException(
"Can't use both ItemsSource and Items collection at the same time.");

this.Items?.Add(args.Message);
this.Items.Add(args.Message);

if (args.Message is INotificationAnimation)
if (args.Message is INotificationAnimation animatableMessage)
{
var animatableMessage = args.Message as INotificationAnimation;
var animation = animatableMessage.AnimationIn;
if (animatableMessage.Animates && animatableMessage.AnimatableElement != null
&& animation != null && animatableMessage.AnimationInDependencyProperty != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="ActionExtensions.cs" />
<Compile Include="ContentLocation.cs" />
<Compile Include="Controls\NotificationMessage.cs" />
<Compile Include="Controls\NotificationMessageButton.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Enterwell.Clients.Wpf.Notifications
/// The animation properties for a notification message or some
/// other item.
/// </summary>
interface INotificationAnimation
public interface INotificationAnimation
{
/// <summary>
/// Gets or sets whether the item animates in and out.
Expand Down
Loading

0 comments on commit 0ac533d

Please sign in to comment.