Skip to content

Commit

Permalink
Merge pull request #1 from MahApps/develop
Browse files Browse the repository at this point in the history
Updating....
  • Loading branch information
timunie authored Jul 12, 2019
2 parents fbc736f + 1f793da commit d5c3750
Show file tree
Hide file tree
Showing 11 changed files with 216 additions and 55 deletions.
28 changes: 17 additions & 11 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,18 @@ We use these awesome tools to build and develop MahApps.Metro.
</a>
</div>

## Contributors

This project exists thanks to all the people who contribute.

<a href="https://github.com/MahApps/MahApps.Metro/graphs/contributors"><img src="https://opencollective.com/mahappsmetro/contributors.svg?width=890&button=false" /></a>

## Sponsorship

This framework is free and can be used for free, open source and commercial applications. MahApps.Metro (all code, NuGets and binaries) are under the [MIT License (MIT)](./LICENSE). It's tested, used and contributed by many awesome people. So hit the magic :star: button, we appreciate it!!! :pray: Thx! :squirrel:

The core team members, MahApps.Metro contributors and contributors in the ecosystem do this open source work in their free time. If you use MahApps.Metro a serious task, and you'd like us to invest more time on it, please donate. This project increases your income/productivity/usabilty too.

## Why charge/sponsor for open source?

* [Open-Source Maintainers are Jerks! | Nick Randolph & Geoffrey Huntley](https://vimeo.com/296579853)
* [FOSS is free as in toilet | Geoffroy Couprie](http://unhandledexpression.com/general/2018/11/27/foss-is-free-as-in-toilet.html)
* [How to Charge for your Open Source | Mike Perham](https://www.mikeperham.com/2015/11/23/how-to-charge-for-your-open-source/)
* [Sustain OSS: The Report](https://sustainoss.org/assets/pdf/SustainOSS-west-2017-report.pdf)
* [Open Source Maintainers Owe You Nothing | Mike McQuaid](https://mikemcquaid.com/2018/03/19/open-source-maintainers-owe-you-nothing/)
* [Who should fund open source projects? | Jane Elizabeth](https://jaxenter.com/who-funds-open-source-projects-133222.html)
* [Apply at OSS Inc today| Ryan Chenkie](https://twitter.com/ryanchenkie/status/1067801413974032385)
* [The Ethics of Unpaid Labor and the OSS Community | Ashe Dryden](https://www.ashedryden.com/blog/the-ethics-of-unpaid-labor-and-the-oss-community)

## Backers

[Become a backer](https://opencollective.com/mahappsmetro#backer) and show your support to our open source project.
Expand Down Expand Up @@ -186,6 +181,17 @@ Does your company use MahApps.Metro? Ask your manager or marketing team if your
<a href="https://opencollective.com/mahappsmetro/tiers/sponsor/3/website" target="_blank"><img src="https://opencollective.com/mahappsmetro/tiers/sponsor/3/avatar"></a>
<a href="https://opencollective.com/mahappsmetro/tiers/sponsor/4/website" target="_blank"><img src="https://opencollective.com/mahappsmetro/tiers/sponsor/4/avatar"></a>

## Why charge/sponsor for open source?

* [Open-Source Maintainers are Jerks! | Nick Randolph & Geoffrey Huntley](https://vimeo.com/296579853)
* [FOSS is free as in toilet | Geoffroy Couprie](http://unhandledexpression.com/general/2018/11/27/foss-is-free-as-in-toilet.html)
* [How to Charge for your Open Source | Mike Perham](https://www.mikeperham.com/2015/11/23/how-to-charge-for-your-open-source/)
* [Sustain OSS: The Report](https://sustainoss.org/assets/pdf/SustainOSS-west-2017-report.pdf)
* [Open Source Maintainers Owe You Nothing | Mike McQuaid](https://mikemcquaid.com/2018/03/19/open-source-maintainers-owe-you-nothing/)
* [Who should fund open source projects? | Jane Elizabeth](https://jaxenter.com/who-funds-open-source-projects-133222.html)
* [Apply at OSS Inc today| Ryan Chenkie](https://twitter.com/ryanchenkie/status/1067801413974032385)
* [The Ethics of Unpaid Labor and the OSS Community | Ashe Dryden](https://www.ashedryden.com/blog/the-ethics-of-unpaid-labor-and-the-oss-community)

## Examples

* [Azuser](https://github.com/Inzanit/azuser) by [@Inzanit](https://github.com/Inzanit) Azure SQL Server User Management
Expand Down
1 change: 1 addition & 0 deletions src/MahApps.Metro.Samples/MahApps.Metro.Demo/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

<Style BasedOn="{StaticResource MetroValidationPopup}" TargetType="{x:Type controls:CustomValidationPopup}">
<Setter Property="CloseOnMouseLeftButtonDown" Value="False" />
<Setter Property="ShowValidationErrorOnMouseOver" Value="False" />
</Style>

<!-- quick change of the collapse storyboard duration -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,10 @@
OnLabel="Enabled"
Style="{StaticResource MahApps.Metro.Styles.ToggleSwitch.Win10}" />
<Controls:ToggleSwitch x:Name="visibleSwitch"
Controls:ValidationHelper.ShowValidationErrorOnMouseOver="True"
Controls:ValidationHelper.CloseOnMouseLeftButtonDown="True"
Margin="{StaticResource ControlMargin}"
IsChecked="False"
IsChecked="{Binding IsToggleSwitchVisible, ValidatesOnDataErrors=True}"
OffLabel="Collapsed"
OnLabel="Visible"
Style="{StaticResource MahApps.Metro.Styles.ToggleSwitch.Win10}" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,11 @@ public string this[string columnName]
return "No time given!";
}

if (columnName == nameof(IsToggleSwitchVisible) && !IsToggleSwitchVisible)
{
return "There is something hidden... \nActivate me to show it up.";
}

return null;
}
}
Expand Down Expand Up @@ -455,5 +460,7 @@ private void ToggleIconScaling(object obj)
public bool IsScaleDownLargerFrame => ((MetroWindow)Application.Current.MainWindow).IconScalingMode == MultiFrameImageMode.ScaleDownLargerFrame;

public bool IsNoScaleSmallerFrame => ((MetroWindow)Application.Current.MainWindow).IconScalingMode == MultiFrameImageMode.NoScaleSmallerFrame;

public bool IsToggleSwitchVisible { get; set; }
}
}
12 changes: 9 additions & 3 deletions src/MahApps.Metro/Behaviors/WindowsSettingBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ private void AssociatedObject_SourceInitialized(object sender, EventArgs e)
window.Closing += this.AssociatedObject_Closing;
window.Closed += this.AssociatedObject_Closed;

Application.Current.SessionEnding += this.CurrentApplicationSessionEnding;
if (Application.Current != null) // In case the Window is hosted in a WinForm app
{
Application.Current.SessionEnding += this.CurrentApplicationSessionEnding;
}
}

private void AssociatedObject_Closing(object sender, System.ComponentModel.CancelEventArgs e)
Expand All @@ -63,7 +66,7 @@ private void CurrentApplicationSessionEnding(object sender, SessionEndingCancelE
private void AssociatedObject_StateChanged(object sender, EventArgs e)
{
// save the settings on this state change, because hidden windows gets no window placements
// all the saving stuff could be so much easier with ReactiveUI :-D
// all the saving stuff could be so much easier with ReactiveUI :-D
if (this.AssociatedObject?.WindowState == WindowState.Minimized)
{
this.SaveWindowState();
Expand All @@ -87,7 +90,10 @@ private void CleanUp(string fromWhere)
window.Closed -= this.AssociatedObject_Closed;
window.SourceInitialized -= this.AssociatedObject_SourceInitialized;

Application.Current.SessionEnding -= this.CurrentApplicationSessionEnding;
if (Application.Current != null) // In case the Window is hosted in a WinForm app
{
Application.Current.SessionEnding -= this.CurrentApplicationSessionEnding;
}
}

#pragma warning disable 618
Expand Down
73 changes: 56 additions & 17 deletions src/MahApps.Metro/Controls/CustomValidationPopup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,61 @@ namespace MahApps.Metro.Controls
/// </summary>
public class CustomValidationPopup : Popup
{
public static readonly DependencyProperty CloseOnMouseLeftButtonDownProperty = DependencyProperty.Register("CloseOnMouseLeftButtonDown", typeof(bool), typeof(CustomValidationPopup), new PropertyMetadata(true));

private Window hostWindow;

public CustomValidationPopup()
public static readonly DependencyProperty CloseOnMouseLeftButtonDownProperty
= DependencyProperty.Register(nameof(CloseOnMouseLeftButtonDown),
typeof(bool),
typeof(CustomValidationPopup),
new PropertyMetadata(true));

/// <summary>
/// Gets or sets whether if the popup can be closed by left mouse button down.
/// </summary>
public bool CloseOnMouseLeftButtonDown
{
this.Loaded += this.CustomValidationPopup_Loaded;
this.Opened += this.CustomValidationPopup_Opened;
get { return (bool)this.GetValue(CloseOnMouseLeftButtonDownProperty); }
set { this.SetValue(CloseOnMouseLeftButtonDownProperty, value); }
}

public static readonly DependencyProperty ShowValidationErrorOnMouseOverProperty
= DependencyProperty.RegisterAttached(nameof(ShowValidationErrorOnMouseOver),
typeof(bool),
typeof(CustomValidationPopup),
new PropertyMetadata(false));

/// <summary>
/// Gets/sets if the popup can be closed by left mouse button down.
/// Gets or sets whether the validation error text will be shown when hovering the validation triangle.
/// </summary>
public bool CloseOnMouseLeftButtonDown
public bool ShowValidationErrorOnMouseOver
{
get { return (bool)GetValue(CloseOnMouseLeftButtonDownProperty); }
set { SetValue(CloseOnMouseLeftButtonDownProperty, value); }
get { return (bool)this.GetValue(ShowValidationErrorOnMouseOverProperty); }
set { this.SetValue(ShowValidationErrorOnMouseOverProperty, value); }
}

public CustomValidationPopup()
{
this.Loaded += this.CustomValidationPopup_Loaded;
this.Opened += this.CustomValidationPopup_Opened;
}

protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
{
if (CloseOnMouseLeftButtonDown)
if (this.CloseOnMouseLeftButtonDown)
{
this.SetCurrentValue(IsOpenProperty, false);
}
else
{
this.SetCurrentValue(Popup.IsOpenProperty, false);
var adornedElement = this.GetAdornedElement();
if (adornedElement != null && ValidationHelper.GetCloseOnMouseLeftButtonDown(adornedElement))
{
this.SetCurrentValue(IsOpenProperty, false);
}
else
{
e.Handled = true;
}
}
}

Expand Down Expand Up @@ -98,6 +129,7 @@ private void CustomValidationPopup_Unloaded(object sender, RoutedEventArgs e)
{
target.SizeChanged -= this.hostWindow_SizeOrLocationChanged;
}

if (this.hostWindow != null)
{
this.hostWindow.LocationChanged -= this.hostWindow_SizeOrLocationChanged;
Expand All @@ -106,24 +138,30 @@ private void CustomValidationPopup_Unloaded(object sender, RoutedEventArgs e)
this.hostWindow.Activated -= this.hostWindow_Activated;
this.hostWindow.Deactivated -= this.hostWindow_Deactivated;
}

this.Unloaded -= this.CustomValidationPopup_Unloaded;
this.Opened -= this.CustomValidationPopup_Opened;
this.hostWindow = null;
}

private UIElement GetAdornedElement()
{
var placeholder = this.PlacementTarget is FrameworkElement target ? target.DataContext as AdornedElementPlaceholder : null;
return placeholder?.AdornedElement;
}

private void hostWindow_StateChanged(object sender, EventArgs e)
{
if (this.hostWindow != null && this.hostWindow.WindowState != WindowState.Minimized)
{
var target = this.PlacementTarget as FrameworkElement;
var holder = target != null ? target.DataContext as AdornedElementPlaceholder : null;
if (holder != null && holder.AdornedElement != null)
var adornedElement = this.GetAdornedElement();
if (adornedElement != null)
{
this.PopupAnimation = PopupAnimation.None;
this.IsOpen = false;
var errorTemplate = holder.AdornedElement.GetValue(Validation.ErrorTemplateProperty);
holder.AdornedElement.SetValue(Validation.ErrorTemplateProperty, null);
holder.AdornedElement.SetValue(Validation.ErrorTemplateProperty, errorTemplate);
var errorTemplate = adornedElement.GetValue(Validation.ErrorTemplateProperty);
adornedElement.SetValue(Validation.ErrorTemplateProperty, null);
adornedElement.SetValue(Validation.ErrorTemplateProperty, errorTemplate);
}
}
}
Expand Down Expand Up @@ -157,6 +195,7 @@ private void SetTopmostState(bool isTop)
{
return;
}

var hwnd = hwndSource.Handle;

#pragma warning disable 618
Expand Down
8 changes: 4 additions & 4 deletions src/MahApps.Metro/Controls/Dialogs/DialogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public static Task<string> ShowInputAsync(this MetroWindow window, string title,
}));
}).Unwrap();
}

/// <summary>
/// Creates a MessageDialog inside of the current window.
/// </summary>
Expand Down Expand Up @@ -584,7 +584,7 @@ private static Window CreateExternalWindow()
private static Window SetupExternalDialogWindow(BaseMetroDialog dialog, [CanBeNull] Window windowOwner = null)
{
var win = CreateExternalWindow();
win.Owner = windowOwner ?? Application.Current.MainWindow;
win.Owner = windowOwner ?? Application.Current?.MainWindow;
win.Width = SystemParameters.PrimaryScreenWidth;
win.MinHeight = SystemParameters.PrimaryScreenHeight / 4.0;
win.SizeToContent = SizeToContent.Height;
Expand Down Expand Up @@ -618,7 +618,7 @@ private static Window CreateModalExternalWindow(MetroWindow window)
win.Width = window.ActualWidth;
win.MaxHeight = window.ActualHeight;
win.SizeToContent = SizeToContent.Height;

return win;
}

Expand All @@ -644,7 +644,7 @@ public static LoginDialogData ShowModalLoginExternal(this MetroWindow window, st
};

SetDialogFontSizes(settings, dialog);

win.Content = dialog;

LoginDialogData result = null;
Expand Down
10 changes: 5 additions & 5 deletions src/MahApps.Metro/Controls/Dialogs/ProgressDialogController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void SetProgress(double value)
}

/// <summary>
/// Gets/Sets the minimum restriction of the progress Value property
/// Gets/Sets the minimum restriction of the progress Value property.
/// </summary>
public double Minimum
{
Expand All @@ -101,7 +101,7 @@ public double Minimum
}

/// <summary>
/// Gets/Sets the maximum restriction of the progress Value property
/// Gets/Sets the maximum restriction of the progress Value property.
/// </summary>
public double Maximum
{
Expand All @@ -128,9 +128,9 @@ public void SetTitle(string title)
}

/// <summary>
/// Sets the dialog's progress bar brush
/// Sets the dialog's progress bar brush.
/// </summary>
/// <param name="brush">The brush to use for the progress bar's foreground</param>
/// <param name="brush">The brush to use for the progress bar's foreground.</param>
public void SetProgressBarForegroundBrush(Brush brush)
{
this.WrappedDialog.Invoke(() => this.WrappedDialog.ProgressBarForeground = brush);
Expand Down Expand Up @@ -162,4 +162,4 @@ public Task CloseAsync()
}));
}
}
}
}
66 changes: 66 additions & 0 deletions src/MahApps.Metro/Controls/Helper/ValidationHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System.ComponentModel;
using System.Windows;

namespace MahApps.Metro.Controls
{
public static class ValidationHelper
{
/// <summary>
/// Identifies the CloseOnMouseLeftButtonDown attached property.
/// </summary>
public static readonly DependencyProperty CloseOnMouseLeftButtonDownProperty
= DependencyProperty.RegisterAttached("CloseOnMouseLeftButtonDown",
typeof(bool),
typeof(ValidationHelper),
new PropertyMetadata(false));

/// <summary>
/// Gets whether if the popup can be closed by left mouse button down.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(UIElement))]
public static bool GetCloseOnMouseLeftButtonDown(UIElement element)
{
return (bool)element.GetValue(CloseOnMouseLeftButtonDownProperty);
}

/// <summary>
/// Sets whether if the popup can be closed by left mouse button down.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(UIElement))]
public static void SetCloseOnMouseLeftButtonDown(UIElement element, bool value)
{
element.SetValue(CloseOnMouseLeftButtonDownProperty, value);
}

/// <summary>
/// Identifies the ShowValidationErrorOnMouseOver attached property.
/// </summary>
public static readonly DependencyProperty ShowValidationErrorOnMouseOverProperty
= DependencyProperty.RegisterAttached("ShowValidationErrorOnMouseOver",
typeof(bool),
typeof(ValidationHelper),
new PropertyMetadata(false));

/// <summary>
/// Gets whether the validation error text will be shown when hovering the validation triangle.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(UIElement))]
public static bool GetShowValidationErrorOnMouseOver(UIElement element)
{
return (bool)element.GetValue(ShowValidationErrorOnMouseOverProperty);
}

/// <summary>
/// Sets whether the validation error text will be shown when hovering the validation triangle.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(UIElement))]
public static void SetShowValidationErrorOnMouseOver(UIElement element, bool value)
{
element.SetValue(ShowValidationErrorOnMouseOverProperty, value);
}
}
}
Loading

0 comments on commit d5c3750

Please sign in to comment.