Growl multi-window support

This commit is contained in:
NaBian committed 2019-03-24 16:54:42 +08:00
1 parent 7c331c1e60
commit 0cdb6d7543
14 files changed
+160 -36

No files matched your search

+2 -2
View File
@@ -15,12 +15,12 @@ namespace HandyControl.Controls
{
var collection = Interaction.GetBehaviors(panel);
var oldBehavior = GetTempFluidMoveBehavior(panel);
collection.Remove(oldBehavior);
collection.ItemRemoved(oldBehavior);
panel.SetCurrentValue(TempFluidMoveBehaviorProperty, DependencyProperty.UnsetValue);
if (e.NewValue is FluidMoveBehavior behavior)
{
collection.Add(behavior);
collection.ItemAdded(behavior);
SetTempFluidMoveBehavior(panel, behavior);
}
}
+27 -21
View File
@@ -4,7 +4,6 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Threading;
using HandyControl.Data;
using HandyControl.Interactivity;
@@ -43,11 +42,6 @@ namespace HandyControl.Controls
private int _waitTime = 6;
/// <summary>
/// 消息容器
/// </summary>
public static Panel GrowlPanel { get; set; }
/// <summary>
/// 计数
/// </summary>
@@ -65,14 +59,21 @@ namespace HandyControl.Controls
CommandBindings.Add(new CommandBinding(ControlCommands.Close, ButtonClose_OnClick));
CommandBindings.Add(new CommandBinding(ControlCommands.Cancel, ButtonCancel_OnClick));
CommandBindings.Add(new CommandBinding(ControlCommands.Confirm, ButtonOk_OnClick));
MouseEnter += Growl_MouseEnter;
MouseLeave += Growl_MouseLeave;
}
private void Growl_MouseLeave(object sender, MouseEventArgs e) => _buttonClose.Collapse();
protected override void OnMouseEnter(MouseEventArgs e)
{
base.OnMouseEnter(e);
private void Growl_MouseEnter(object sender, MouseEventArgs e) => _buttonClose.Show(_showCloseButton);
_buttonClose.Show(_showCloseButton);
}
protected override void OnMouseLeave(MouseEventArgs e)
{
base.OnMouseLeave(e);
_buttonClose.Collapse();
}
public override void OnApplyTemplate()
{
@@ -93,6 +94,11 @@ namespace HandyControl.Controls
private Func<bool, bool> ActionBeforeClose { get; set; }
/// <summary>
/// 消息容器
/// </summary>
public static Panel GrowlPanel { get; set; }
internal static readonly DependencyProperty CancelStrProperty = DependencyProperty.Register(
"CancelStr", typeof(string), typeof(Growl), new PropertyMetadata(default(string)));
@@ -120,7 +126,7 @@ namespace HandyControl.Controls
public static readonly DependencyProperty GrowlParentProperty = DependencyProperty.RegisterAttached(
"GrowlParent", typeof(bool), typeof(Growl), new PropertyMetadata(ValueBoxes.FalseBox, (o, args) =>
{
if (o is Panel panel)
if ((bool)args.NewValue && o is Panel panel)
{
SetGrowlPanel(panel);
}
@@ -226,14 +232,8 @@ namespace HandyControl.Controls
menuItem
}
};
var behavior = new FluidMoveBehavior
{
AppliesTo = FluidMoveScope.Children,
Duration = new Duration(TimeSpan.FromMilliseconds(400)),
EaseY = new PowerEase()
};
var collection = Interaction.GetBehaviors(GrowlPanel);
collection.Add(behavior);
PanelElement.SetFluidMoveBehavior(GrowlPanel, ResourceHelper.GetResource<FluidMoveBehavior>(ResourceToken.BehaviorXY400));
}
private void Update()
@@ -451,7 +451,13 @@ namespace HandyControl.Controls
var transform = new TranslateTransform();
_gridMain.RenderTransform = transform;
var animation = AnimationHelper.CreateAnimation(MaxWidth);
animation.Completed += delegate { GrowlPanel.Children.Remove(this); };
animation.Completed += (s, e) =>
{
if (Parent is Panel panel)
{
panel.Children.Remove(this);
}
};
transform.BeginAnimation(TranslateTransform.XProperty, animation);
}
+1
View File
@@ -64,5 +64,6 @@
internal const string TabItemCapsuleVerticalLast = nameof(TabItemCapsuleVerticalLast);
internal const string BehaviorXY400 = nameof(BehaviorXY400);
}
}
@@ -22,14 +22,14 @@ namespace HandyControl.Interactivity
internal override void ItemAdded(Behavior item)
{
if (AssociatedObject == null)
if (item == null || AssociatedObject == null)
return;
item.Attach(AssociatedObject);
}
internal override void ItemRemoved(Behavior item)
{
if (((IAttachedObject) item).AssociatedObject == null)
if (((IAttachedObject) item)?.AssociatedObject == null)
return;
item.Detach();
}
+7
View File
@@ -381,6 +381,9 @@
<Compile Include="Window\CustomNonClientAreaWindow.xaml.cs">
<DependentUpon>CustomNonClientAreaWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Window\GrowlDemoWindow.xaml.cs">
<DependentUpon>GrowlDemoWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Window\NoNonClientAreaDragableWindow.xaml.cs">
<DependentUpon>NoNonClientAreaDragableWindow.xaml</DependentUpon>
</Compile>
@@ -764,6 +767,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Window\GrowlDemoWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Window\NoNonClientAreaDragableWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
+1 -1
View File
@@ -33,7 +33,7 @@
<userControl:MainContent Grid.Column="1"/>
<GridSplitter Grid.Column="1" HorizontalAlignment="Left" Width="4" Background="Transparent" BorderThickness="1,0,0,0" BorderBrush="{DynamicResource BorderBrush}"/>
<controls:ScrollViewer Grid.Column="1" VerticalScrollBarVisibility="Hidden" HorizontalAlignment="Right" IsEnableInertia="True" IsPenetrating="True">
<StackPanel controls:Growl.GrowlParent="True" VerticalAlignment="Top" Margin="0,10,10,10"/>
<StackPanel Name="GrowlPanel" VerticalAlignment="Top" Margin="0,10,10,10"/>
</controls:ScrollViewer>
</Grid>
</controls:BlurWindow>
+18 -1
View File
@@ -1,4 +1,7 @@
namespace HandyControlDemo
using System;
using HandyControl.Controls;
namespace HandyControlDemo
{
public partial class MainWindow
{
@@ -6,5 +9,19 @@
{
InitializeComponent();
}
protected override void OnActivated(EventArgs e)
{
base.OnActivated(e);
Growl.SetGrowlParent(GrowlPanel, true);
}
protected override void OnDeactivated(EventArgs e)
{
base.OnDeactivated(e);
Growl.SetGrowlParent(GrowlPanel, false);
}
}
}
+18
View File
@@ -519,6 +519,15 @@ namespace HandyControlDemo.Properties.Langs {
}
}
/// <summary>
/// 查找类似 消息通知示例 的本地化字符串。
/// </summary>
public static string GrowlDemo {
get {
return ResourceManager.GetString("GrowlDemo", resourceCulture);
}
}
/// <summary>
/// 查找类似 连接失败,请检查网络! 的本地化字符串。
/// </summary>
@@ -672,6 +681,15 @@ namespace HandyControlDemo.Properties.Langs {
}
}
/// <summary>
/// 查找类似 新建窗口 的本地化字符串。
/// </summary>
public static string NewWindow {
get {
return ResourceManager.GetString("NewWindow", resourceCulture);
}
}
/// <summary>
/// 查找类似 下一步 的本地化字符串。
/// </summary>
@@ -522,4 +522,10 @@
<data name="PleaseWait" xml:space="preserve">
<value>Please wait...</value>
</data>
<data name="GrowlDemo" xml:space="preserve">
<value>Growl demo</value>
</data>
<data name="NewWindow" xml:space="preserve">
<value>New window</value>
</data>
</root>
@@ -522,4 +522,10 @@
<data name="PleaseWait" xml:space="preserve">
<value>请稍后...</value>
</data>
<data name="GrowlDemo" xml:space="preserve">
<value>消息通知示例</value>
</data>
<data name="NewWindow" xml:space="preserve">
<value>新建窗口</value>
</data>
</root>
@@ -6,14 +6,17 @@
DataContext="{Binding GrowlDemo,Source={StaticResource Locator}}"
Background="{DynamicResource RegionBrush}">
<controls:TransitioningContentControl>
<WrapPanel Margin="32" VerticalAlignment="Center">
<Button Command="{Binding InfoCmd}" Content="{x:Static langs:Lang.Info}" Margin="0,5,5,5" Style="{StaticResource ButtonInfo}"/>
<Button Command="{Binding SuccessCmd}" Content="{x:Static langs:Lang.Success}" Margin="5" Style="{StaticResource ButtonSuccess}"/>
<Button Command="{Binding WarningCmd}" Content="{x:Static langs:Lang.Warning}" Margin="5" Style="{StaticResource ButtonWarning}"/>
<Button Command="{Binding ErrorCmd}" Content="{x:Static langs:Lang.Error}" Margin="5" Style="{StaticResource ButtonDanger}"/>
<Button Command="{Binding AskCmd}" Content="{x:Static langs:Lang.Ask}" Margin="5" Background="BlueViolet" Foreground="White"/>
<Button Command="{Binding FatalCmd}" Content="{x:Static langs:Lang.Fatal}" Margin="5,0"/>
<Button Command="{Binding ClearCmd}" Content="{x:Static langs:Lang.Clear}" Margin="5,0,0,0" Style="{StaticResource ButtonPrimary}"/>
</WrapPanel>
<StackPanel Margin="32">
<WrapPanel VerticalAlignment="Center">
<Button Command="{Binding InfoCmd}" Content="{x:Static langs:Lang.Info}" Margin="0,5,5,5" Style="{StaticResource ButtonInfo}"/>
<Button Command="{Binding SuccessCmd}" Content="{x:Static langs:Lang.Success}" Margin="5" Style="{StaticResource ButtonSuccess}"/>
<Button Command="{Binding WarningCmd}" Content="{x:Static langs:Lang.Warning}" Margin="5" Style="{StaticResource ButtonWarning}"/>
<Button Command="{Binding ErrorCmd}" Content="{x:Static langs:Lang.Error}" Margin="5" Style="{StaticResource ButtonDanger}"/>
<Button Command="{Binding AskCmd}" Content="{x:Static langs:Lang.Ask}" Margin="5" Background="BlueViolet" Foreground="White"/>
<Button Command="{Binding FatalCmd}" Content="{x:Static langs:Lang.Fatal}" Margin="5,0"/>
<Button Command="{Binding ClearCmd}" Content="{x:Static langs:Lang.Clear}" Margin="5,0,0,0" Style="{StaticResource ButtonPrimary}"/>
</WrapPanel>
<Button Command="{Binding NewWindowCmd}" Content="{x:Static langs:Lang.NewWindow}" Margin="0,5,0,0" HorizontalAlignment="Left"/>
</StackPanel>
</controls:TransitioningContentControl>
</UserControl>
@@ -2,6 +2,7 @@
using GalaSoft.MvvmLight.Command;
using HandyControl.Controls;
using HandyControl.Data;
using HandyControlDemo.Window;
namespace HandyControlDemo.ViewModel
{
@@ -44,5 +45,8 @@ namespace HandyControlDemo.ViewModel
public RelayCommand ClearCmd => new Lazy<RelayCommand>(() =>
new RelayCommand(Growl.Clear)).Value;
public RelayCommand NewWindowCmd => new Lazy<RelayCommand>(() =>
new RelayCommand(() => new GrowlDemoWindow().Show())).Value;
}
}
@@ -0,0 +1,29 @@
<Window x:Class="HandyControlDemo.Window.GrowlDemoWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:HandyControl.Controls;assembly=HandyControl"
xmlns:langs="clr-namespace:HandyControlDemo.Properties.Langs"
DataContext="{Binding GrowlDemo,Source={StaticResource Locator}}"
Title="{x:Static langs:Lang.GrowlDemo}"
Width="800"
Height="500">
<controls:TransitioningContentControl>
<controls:SimplePanel>
<StackPanel Margin="32">
<WrapPanel HorizontalAlignment="Left" VerticalAlignment="Top">
<Button Command="{Binding InfoCmd}" Content="{x:Static langs:Lang.Info}" Margin="0,5,5,5" Style="{StaticResource ButtonInfo}"/>
<Button Command="{Binding SuccessCmd}" Content="{x:Static langs:Lang.Success}" Margin="5" Style="{StaticResource ButtonSuccess}"/>
<Button Command="{Binding WarningCmd}" Content="{x:Static langs:Lang.Warning}" Margin="5" Style="{StaticResource ButtonWarning}"/>
<Button Command="{Binding ErrorCmd}" Content="{x:Static langs:Lang.Error}" Margin="5" Style="{StaticResource ButtonDanger}"/>
<Button Command="{Binding AskCmd}" Content="{x:Static langs:Lang.Ask}" Margin="5" Background="BlueViolet" Foreground="White"/>
<Button Command="{Binding FatalCmd}" Content="{x:Static langs:Lang.Fatal}" Margin="5,0"/>
<Button Command="{Binding ClearCmd}" Content="{x:Static langs:Lang.Clear}" Margin="5,0,0,0" Style="{StaticResource ButtonPrimary}"/>
</WrapPanel>
<Button Command="{Binding NewWindowCmd}" Content="{x:Static langs:Lang.NewWindow}" HorizontalAlignment="Left" Margin="0,5,0,0"/>
</StackPanel>
<controls:ScrollViewer VerticalScrollBarVisibility="Hidden" HorizontalAlignment="Right" IsEnableInertia="True" IsPenetrating="True">
<StackPanel Name="GrowlPanel" VerticalAlignment="Top" Margin="0,10,10,10"/>
</controls:ScrollViewer>
</controls:SimplePanel>
</controls:TransitioningContentControl>
</Window>
@@ -0,0 +1,27 @@
using System;
using HandyControl.Controls;
namespace HandyControlDemo.Window
{
public partial class GrowlDemoWindow
{
public GrowlDemoWindow()
{
InitializeComponent();
}
protected override void OnActivated(EventArgs e)
{
base.OnActivated(e);
Growl.SetGrowlParent(GrowlPanel, true);
}
protected override void OnDeactivated(EventArgs e)
{
base.OnDeactivated(e);
Growl.SetGrowlParent(GrowlPanel, false);
}
}
}