Code modernising (#8)

* Applied some code conventions, used more current language features which should improve readability and making it easier to re-factor / modify. Also fixed some typos in documentation.
* Changes based on PR conversation for the SystemInfo
* Some modifications due to conversations on the PR, especially I removed the FlagsAttribute on the BalloonFlags.
* Removed Silverlight targeting in code.
This commit is contained in:
Robin Krom
2019-07-16 14:10:00 +02:00
committed by Philipp Sumi
parent 90051586d4
commit 23186feefe
36 changed files with 611 additions and 754 deletions

View File

@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using Hardcodet.Wpf.TaskbarNotification;
using System.Windows;
namespace Samples
{

View File

@@ -62,7 +62,7 @@ namespace Samples.Commands
/// </param>
public virtual bool CanExecute(object parameter)
{
return IsDesignMode ? false : true;
return !IsDesignMode;
}
@@ -82,12 +82,12 @@ namespace Samples.Commands
/// Resolves the window that owns the TaskbarIcon class.
/// </summary>
/// <param name="commandParameter"></param>
/// <returns></returns>
/// <returns>Window</returns>
protected Window GetTaskbarWindow(object commandParameter)
{
if (IsDesignMode) return null;
//get the showcase window off the taskbaricon
// get the showcase window off the taskbar icon
var tb = commandParameter as TaskbarIcon;
return tb == null ? null : TryFindParent<Window>(tb);
}
@@ -97,14 +97,13 @@ namespace Samples.Commands
/// <summary>
/// Finds a parent of a given item on the visual tree.
/// </summary>
/// <typeparam name="T">The type of the queried item.</typeparam>
/// <typeparam name="TParent">The type of the queried item.</typeparam>
/// <param name="child">A direct or indirect child of the
/// queried item.</param>
/// <returns>The first parent item that matches the submitted
/// type parameter. If not matching item can be found, a null
/// reference is being returned.</returns>
public static T TryFindParent<T>(DependencyObject child)
where T : DependencyObject
public static TParent TryFindParent<TParent>(DependencyObject child) where TParent : DependencyObject
{
//get parent item
DependencyObject parentObject = GetParentObject(child);
@@ -113,16 +112,13 @@ namespace Samples.Commands
if (parentObject == null) return null;
//check if the parent matches the type we're looking for
T parent = parentObject as T;
if (parent != null)
if (parentObject is TParent parent)
{
return parent;
}
else
{
//use recursion to proceed with next level
return TryFindParent<T>(parentObject);
}
//use recursion to proceed with next level
return TryFindParent<TParent>(parentObject);
}
/// <summary>
@@ -137,15 +133,14 @@ namespace Samples.Commands
public static DependencyObject GetParentObject(DependencyObject child)
{
if (child == null) return null;
ContentElement contentElement = child as ContentElement;
if (contentElement != null)
if (child is ContentElement contentElement)
{
DependencyObject parent = ContentOperations.GetParent(contentElement);
if (parent != null) return parent;
FrameworkContentElement fce = contentElement as FrameworkContentElement;
return fce != null ? fce.Parent : null;
return fce?.Parent;
}
//if it's not a ContentElement, rely on VisualTreeHelper

View File

@@ -82,17 +82,19 @@ namespace Samples
ShowDialog(new DataBoundToolTipWindow());
}
private void btnMvvm_Click(object sender, System.Windows.RoutedEventArgs e)
private void btnMvvm_Click(object sender, RoutedEventArgs e)
{
ShowDialog(new MvvmSampleWindow());
}
private void btnMainSample_Click(object sender, RoutedEventArgs e)
{
var sampleWindow = new ShowcaseWindow();
var sampleWindow = new ShowcaseWindow
{
Owner = this,
WindowStartupLocation = WindowStartupLocation.CenterScreen
};
sampleWindow.Owner = this;
sampleWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;
sampleWindow.ShowDialog();
}

View File

@@ -1,7 +1,4 @@
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
using System.Windows;
// Setting ComVisible to false makes the types in this assembly not visible

View File

@@ -1,18 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Hardcodet.Wpf.TaskbarNotification;
namespace Samples
@@ -30,10 +20,10 @@ namespace Samples
/// Description
/// </summary>
public static readonly DependencyProperty BalloonTextProperty =
DependencyProperty.Register("BalloonText",
DependencyProperty.Register(nameof(BalloonText),
typeof (string),
typeof (FancyBalloon),
new FrameworkPropertyMetadata(""));
new FrameworkPropertyMetadata(string.Empty));
/// <summary>
/// A property wrapper for the <see cref="BalloonTextProperty"/>

View File

@@ -14,7 +14,7 @@ namespace Samples
/// The number of clicks on the popup button.
/// </summary>
public static readonly DependencyProperty ClickCountProperty =
DependencyProperty.Register("ClickCount",
DependencyProperty.Register(nameof(ClickCount),
typeof (int),
typeof (FancyPopup),
new FrameworkPropertyMetadata(0));

View File

@@ -1,16 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Hardcodet.Wpf.TaskbarNotification;
using System.Windows;
namespace Samples
{
@@ -25,10 +13,10 @@ namespace Samples
/// The tooltip details.
/// </summary>
public static readonly DependencyProperty InfoTextProperty =
DependencyProperty.Register("InfoText",
DependencyProperty.Register(nameof(InfoText),
typeof (string),
typeof (FancyToolTip),
new FrameworkPropertyMetadata(""));
new FrameworkPropertyMetadata(string.Empty));
/// <summary>
/// A property wrapper for the <see cref="InfoTextProperty"/>
@@ -45,7 +33,7 @@ namespace Samples
public FancyToolTip()
{
this.InitializeComponent();
InitializeComponent();
}
}
}

View File

@@ -1,16 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Controls;
namespace Samples
{

View File

@@ -1,15 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows;
namespace Samples.Tutorials.ToolTips
{

View File

@@ -1,16 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Controls;
namespace Samples.Tutorials.ToolTips
{

View File

@@ -1,15 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows;
namespace Samples.Tutorials.ToolTips
{

View File

@@ -1,15 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows;
namespace Samples.Tutorials.Popups
{

View File

@@ -1,7 +1,4 @@
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows;
namespace Samples.Tutorials.ContextMenus
{
@@ -24,12 +21,12 @@ namespace Samples.Tutorials.ContextMenus
base.OnClosing(e);
}
private void MyNotifyIcon_TrayContextMenuOpen(object sender, System.Windows.RoutedEventArgs e)
private void MyNotifyIcon_TrayContextMenuOpen(object sender, RoutedEventArgs e)
{
OpenEventCounter.Text = (int.Parse(OpenEventCounter.Text) + 1).ToString();
}
private void MyNotifyIcon_PreviewTrayContextMenuOpen(object sender, System.Windows.RoutedEventArgs e)
private void MyNotifyIcon_PreviewTrayContextMenuOpen(object sender, RoutedEventArgs e)
{
//marking the event as handled suppresses the context menu
e.Handled = (bool) SuppressContextMenu.IsChecked;

View File

@@ -1,17 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Hardcodet.Wpf.TaskbarNotification;
namespace Samples.Tutorials.Balloons
{

View File

@@ -1,15 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows;
namespace Samples.Tutorials.Commands
{

View File

@@ -9,7 +9,7 @@ namespace Samples.Tutorials.MvvmSample
{
public ClockPopup()
{
this.InitializeComponent();
InitializeComponent();
}
}
}