Skip to content

Commit

Permalink
pendingBox & improvements (#41)
Browse files Browse the repository at this point in the history
New Properties:
  TransformControl.RotateAngle
  ComboBoxHelper.ItemsForeground
  ExpanderHelper.HeaderBorderBrush
  ExpanderHelper.HeaderBorderThickness
  ExpanderHelper.ExpandedHeaderBorderBrush
  ExpanderHelper.ExpandedHeaderBorderThickness
  TabControlHelper.ItemsFontSize
  TabControlHelper.ItemsFontFamily
  TabControlHelper.ItemsRibbonLineMargin
  TabControlHelper.ItemsSelectedFontSize
  TabItemHelper.FontSize
  TabItemHelper.FontFamily
  TabItemHelper.RibbonLineMargin
  TabItemHelper.SelectedFontSize
  
Rename:
	TabControlHelper.ItemsHeaderHorizontalAlignment -> ItemsHorizontalAlignment
	TabControlHelper.ItemsHeaderVerticalAlignment -> ItemsHorizontalAlignment
	TabControlHelper.ItemsHeaderHorizontalContentAlignment -> ItemsHorizontalHeaderAlignment
	TabControlHelper.ItemsHeaderVerticalContentAlignment -> ItemsHorizontalHeaderAlignment
  
Fixup: 
	Drawer might close unexpectedly when a popup in it closes.
  • Loading branch information
Mochengvia authored Nov 27, 2021
1 parent 19427e3 commit b29f59b
Show file tree
Hide file tree
Showing 31 changed files with 1,165 additions and 123 deletions.
39 changes: 34 additions & 5 deletions DotNet/WPF/Src/Samples/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,56 @@
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary>
<pu:MessageBoxXSettings x:Key="setting">

<pu:MessageBoxXSettings x:Key="messageSetting">
<pu:MessageBoxXSettings.ButtonStyle>
<Style TargetType="Button"
BasedOn="{StaticResource {ComponentResourceKey ResourceId=ButtonStyle, TypeInTargetAssembly={x:Type pu:MessageBoxX}}}">
<Setter Property="pu:ButtonHelper.CornerRadius"
Value="4" />
<Style.Triggers >
<Style.Triggers>
<Trigger Property="IsDefault"
Value="True">
<Setter Property="Foreground"
Value="#FFFFFF"/>
Value="#FFFFFF" />
<Setter Property="Background"
Value="#80BEE8"/>
Value="#80BEE8" />
</Trigger>
</Style.Triggers>
</Style>
</pu:MessageBoxXSettings.ButtonStyle>
</pu:MessageBoxXSettings>


<pu:PendingBoxSettings x:Key="pendingSetting">
<pu:PendingBoxSettings.SpinnerStyle>
<Style BasedOn="{StaticResource {ComponentResourceKey ResourceId=SpinnerStyle, TypeInTargetAssembly={x:Type pu:PendingBox}}}"
TargetType="pu:Spinner">
<Setter Property="SpinnerStyle"
Value="Ring2" />
<Setter Property="GlyphBrush"
Value="#6CBCEA" />
</Style>
</pu:PendingBoxSettings.SpinnerStyle>
<pu:PendingBoxSettings.CancelButtonStyle>
<!--Attention : CancelButtonStyle in PendingBox does not support Helpers in PanuonUI-->
<Style BasedOn="{StaticResource {ComponentResourceKey ResourceId=CancelButtonStyle, TypeInTargetAssembly={x:Type pu:PendingBox}}}"
TargetType="Button">
<Setter Property="Background"
Value="#6CBCEA" />
<Setter Property="Foreground"
Value="White" />
<Style.Triggers>
<Trigger Property="IsPressed"
Value="True">
<Setter Property="Background"
Value="#6CABEA" />
</Trigger>
</Style.Triggers>
</Style>
</pu:PendingBoxSettings.CancelButtonStyle>
</pu:PendingBoxSettings>

</ResourceDictionary>
<ResourceDictionary Source="pack://application:,,,/Panuon.UI.Silver;component/Control.xaml" />
</ResourceDictionary.MergedDictionaries>
Expand Down
3 changes: 3 additions & 0 deletions DotNet/WPF/Src/Samples/Views/MainView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
<Button Margin="10,0,0,0"
Content="NoticeBox"
Click="BtnTestNoticeBox_Click"/>
<Button Margin="10,0,0,0"
Content="PendingBox"
Click="BtnTestPendingBox_Click"/>
</StackPanel>
<ScrollViewer Grid.Row="1"
Margin="0,15,0,0"
Expand Down
10 changes: 7 additions & 3 deletions DotNet/WPF/Src/Samples/Views/MainView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,17 @@ private void BtnTestMessageBoxX_Click(object sender, RoutedEventArgs e)
MessageBoxX.Show(this, "MessageBoxX style configuration is placed in App.xaml. ", "Tips", MessageBoxIcon.Info, DefaultButton.YesOK);
}

private async void BtnTestNoticeBox_Click(object sender, RoutedEventArgs e)
private void BtnTestNoticeBox_Click(object sender, RoutedEventArgs e)
{
var handler = NoticeBox.Show("NoticeBox style configuration is placed in App.xaml. ", "Tips", MessageBoxIcon.Info, 3000);
//handler.Click += ...
}

private void BtnTestPendingBox_Click(object sender, RoutedEventArgs e)
{
var handler = PendingBox.Show(this, "PendingBox style configuration is placed in App.xaml.", "Caption", true);
//handler.Cancelling += ...
}
#endregion

#region Functions
Expand Down Expand Up @@ -115,8 +121,6 @@ private UIElement CreatePreviewView(WindowX view, object content)
};
return border;
}


#endregion

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,51 +72,42 @@ public override void OnApplyTemplate()
stackPanel.FlowDirection = _setting.InverseButtonsSequence ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;

_okButton = FrameworkElementUtil.FindVisualChild<Button>(this, OKButtonTemplateName);
if (_okButton == null)
if (_okButton != null)
{
throw new Exception($"MessageBoxXSetting : Can not find Button named {OKButtonTemplateName} in ContentTemplate property.");
_okButton.Content = _setting.OKButtonContent;
_okButton.Visibility = (_messageBoxButton == MessageBoxButton.OK || _messageBoxButton == MessageBoxButton.OKCancel) ? Visibility.Visible : Visibility.Collapsed;
_okButton.IsDefault = (_defaultButton == DefaultButton.YesOK && _messageBoxButton == MessageBoxButton.OK);
_okButton.Tag = "OK";
_okButton.Click += Button_Click;
}
_cancelButton = FrameworkElementUtil.FindVisualChild<Button>(this, CancelButtonTemplateName);
if (_cancelButton == null)
if (_cancelButton != null)
{
throw new Exception($"MessageBoxXSetting : Can not find Button named {CancelButtonTemplateName} in ContentTemplate property.");
_cancelButton.Content = _setting.CancelButtonContent;
_cancelButton.Visibility = (_messageBoxButton == MessageBoxButton.OKCancel || _messageBoxButton == MessageBoxButton.YesNoCancel) ? Visibility.Visible : Visibility.Collapsed;
_cancelButton.IsDefault = (_defaultButton == DefaultButton.CancelNo) || (_defaultButton == DefaultButton.NoCancel && _messageBoxButton == MessageBoxButton.OKCancel);
_cancelButton.Tag = "Cancel";
_cancelButton.Click += Button_Click;
}
_yesButton = FrameworkElementUtil.FindVisualChild<Button>(this, YesButtonTemplateName);
if (_yesButton == null)
if (_yesButton != null)
{
throw new Exception($"MessageBoxXSetting : Can not find Button named {YesButtonTemplateName} in ContentTemplate property.");
_yesButton.Content = _setting.YesButtonContent;
_yesButton.Visibility = (_messageBoxButton == MessageBoxButton.YesNo || _messageBoxButton == MessageBoxButton.YesNoCancel) ? Visibility.Visible : Visibility.Collapsed;
_yesButton.IsDefault = (_defaultButton == DefaultButton.YesOK);
_yesButton.Tag = "Yes";
_yesButton.Click += Button_Click;
}
_noButton = FrameworkElementUtil.FindVisualChild<Button>(this, NoButtonTemplateName);
if (_noButton == null)
if (_noButton != null)
{
throw new Exception($"MessageBoxXSetting : Can not find Button named {NoButtonTemplateName} in ContentTemplate property.");
_noButton.Content = _setting.NoButtonContent;
_noButton.Visibility = (_messageBoxButton == MessageBoxButton.YesNo || _messageBoxButton == MessageBoxButton.YesNoCancel) ? Visibility.Visible : Visibility.Collapsed;
_noButton.IsDefault = (_defaultButton == DefaultButton.NoCancel) || (_defaultButton == DefaultButton.CancelNo && (_messageBoxButton == MessageBoxButton.YesNoCancel || _messageBoxButton == MessageBoxButton.OKCancel));
_noButton.Tag = "No";
_noButton.Click += Button_Click;
}

_okButton.Content = _setting.OKButtonContent;
_cancelButton.Content = _setting.CancelButtonContent;
_yesButton.Content = _setting.YesButtonContent;
_noButton.Content = _setting.NoButtonContent;

_okButton.Visibility = (_messageBoxButton == MessageBoxButton.OK || _messageBoxButton == MessageBoxButton.OKCancel) ? Visibility.Visible : Visibility.Collapsed;
_cancelButton.Visibility = (_messageBoxButton == MessageBoxButton.OKCancel || _messageBoxButton == MessageBoxButton.YesNoCancel) ? Visibility.Visible : Visibility.Collapsed;
_yesButton.Visibility = (_messageBoxButton == MessageBoxButton.YesNo || _messageBoxButton == MessageBoxButton.YesNoCancel) ? Visibility.Visible : Visibility.Collapsed;
_noButton.Visibility = (_messageBoxButton == MessageBoxButton.YesNo || _messageBoxButton == MessageBoxButton.YesNoCancel) ? Visibility.Visible : Visibility.Collapsed;

_okButton.IsDefault = (_defaultButton == DefaultButton.YesOK && _messageBoxButton == MessageBoxButton.OK);
_cancelButton.IsDefault = (_defaultButton == DefaultButton.CancelNo) || (_defaultButton == DefaultButton.NoCancel && _messageBoxButton == MessageBoxButton.OKCancel);
_yesButton.IsDefault = (_defaultButton == DefaultButton.YesOK);
_noButton.IsDefault = (_defaultButton == DefaultButton.NoCancel) || (_defaultButton == DefaultButton.CancelNo && (_messageBoxButton == MessageBoxButton.YesNoCancel || _messageBoxButton == MessageBoxButton.OKCancel));

_okButton.Tag = "OK";
_cancelButton.Tag = "Cancel";
_yesButton.Tag = "Yes";
_noButton.Tag = "No";

_okButton.Click += Button_Click;
_cancelButton.Click += Button_Click;
_yesButton.Click += Button_Click;
_noButton.Click += Button_Click;

}), DispatcherPriority.DataBind);

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
using Panuon.UI.Silver.Internal.Implements;
using Panuon.UI.Silver.Internal.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interop;
using System.Windows.Threading;

namespace Panuon.UI.Silver.Internal.Controls
{
class PendingBoxWindow : Window
{
#region Fields
private const string CancelButtonTemplateName = "PART_CancelButton";

private const string MessageTextBlockTemplateName = "PART_MessageTextBlock";

private const string CaptionTextBlockTemplateName = "PART_CaptionTextBlock";

private const string SpinnerTemplateName = "PART_Spinner";

private Button _cancelButton;

private object _cancelButtonContent;

private PendingHandlerImpl _handler;

private WindowX _owner;

private string _messageText;

private string _captionText;

private TextBlock _messageTextBlock;

private bool _canCancel;

private bool _canClose = false;

private Style _cancelButtonStyle;

private Style _spinnerStyle;

private Rect? _ownerRect;
#endregion

#region Ctor
public PendingBoxWindow(Window owner, bool interopOwnersMask, Rect? ownerRect, string message, string caption, bool canCancel, string windowStyle, string cancelButtonStyle, string spinnerStyle, string contentTemplate, object cancelButtonContent, PendingHandlerImpl handler)
{
_captionText = caption;
_messageText = message;
_canCancel = canCancel;

_cancelButtonContent = cancelButtonContent;

_handler = handler;
_handler.SetWindow(this);


Style = XamlUtil.FromXaml<Style>(windowStyle);
ContentTemplate = XamlUtil.FromXaml<DataTemplate>(contentTemplate);
_cancelButtonStyle = XamlUtil.FromXaml<Style>(cancelButtonStyle);
_spinnerStyle = XamlUtil.FromXaml<Style>(spinnerStyle);

WindowStartupLocation = (ownerRect != null || owner == null)
? WindowStartupLocation.Manual
: WindowStartupLocation.CenterOwner;

if (ownerRect == null)
{
Owner = owner;
}
else
{
_ownerRect = ownerRect;
}
if (owner is WindowX ownerX && interopOwnersMask)
{
ownerX.Dispatcher.BeginInvoke(new Action(() =>
{
ownerX.IsMaskVisible = true;
}));
_owner = ownerX;
}
}

#endregion

#region Overrides

#region OnApplyTemplate
public override void OnApplyTemplate()
{
base.OnApplyTemplate();

this.Dispatcher.BeginInvoke(new Action(() =>
{
_cancelButton = FrameworkElementUtil.FindVisualChild<Button>(this, CancelButtonTemplateName);
var captionTextBlock = FrameworkElementUtil.FindVisualChild<TextBlock>(this, CaptionTextBlockTemplateName);
_messageTextBlock = FrameworkElementUtil.FindVisualChild<TextBlock>(this, MessageTextBlockTemplateName);
var spinner = FrameworkElementUtil.FindVisualChild<Spinner>(this, SpinnerTemplateName);

if (_cancelButton != null)
{
_cancelButton.Style = _cancelButtonStyle;
_cancelButton.Content = _cancelButtonContent;
_cancelButton.Visibility = _canCancel ? Visibility.Visible : Visibility.Collapsed;
_cancelButton.Click += CancelButton_Click;
}
if(captionTextBlock != null)
{
captionTextBlock.Text = _captionText;
}
if (_messageTextBlock != null)
{
_messageTextBlock.Text = _messageText;
}
if(spinner != null)
{
spinner.Style = _spinnerStyle;
}

}), DispatcherPriority.DataBind);
}
#endregion

#region OnClosing
protected override void OnClosing(CancelEventArgs e)
{
if (!_canClose)
{
e.Cancel = true;
}
base.OnClosing(e);
}
#endregion

#region OnClosed
protected override void OnClosed(EventArgs e)
{
if(_owner != null)
{
_owner.Dispatcher.BeginInvoke(new Action(() =>
{
if (_owner.OwnedWindows.Count == 0)
{
_owner.IsMaskVisible = false;
}
}));
}
base.OnClosed(e);
_handler.TriggerClosed();
}
#endregion

#region
protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
{
if (_ownerRect is Rect ownerRect)
{
var hwnd = new WindowInteropHelper(this).Handle;

var dpi = Win32Util.GetDpiForWindow(hwnd);
var scaleRatio = dpi / 96d;

var width = (int)(sizeInfo.NewSize.Width * scaleRatio);
var height = (int)(sizeInfo.NewSize.Height * scaleRatio);
var left = ownerRect.X + (ownerRect.Width - width) / 2;
var top = ownerRect.Y + (ownerRect.Height - height) / 2;

Left = left / scaleRatio;
Top = top / scaleRatio;
}
base.OnRenderSizeChanged(sizeInfo);
}
#endregion

#endregion

#region Methods
public new void Close()
{
_canClose = true;
base.Close();
}

public void UpdateMessage(string message)
{
Dispatcher.Invoke(new Action(() =>
{
_messageTextBlock.Text = message;
}));
}
#endregion

#region Event Handlers
private void CancelButton_Click(object sender, RoutedEventArgs e)
{
if (_handler.TriggerCancel())
{
Close();
}
}
#endregion

}
}
Loading

0 comments on commit b29f59b

Please sign in to comment.