mirror of
https://gitee.com/handyorg/HandyControl.git
synced 2024-11-30 02:48:03 +08:00
optimized drawer
This commit is contained in:
parent
27c9458130
commit
3dad11526c
@ -2,7 +2,7 @@
|
||||
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>HandyControl</id>
|
||||
<version>2.5.0</version>
|
||||
<version>2.5.0.2</version>
|
||||
<title>HandyOrg</title>
|
||||
<authors>HandyOrg</authors>
|
||||
<owners>HandyOrg</owners>
|
||||
|
@ -29,7 +29,7 @@
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Margin="10,0,0,0" Text="Header" Style="{StaticResource TextBlockTitle}" HorizontalAlignment="Left"/>
|
||||
<Button CommandTarget="{Binding}" Command="hc:ControlCommands.Close" Grid.Row="0" HorizontalAlignment="Right" Foreground="{DynamicResource PrimaryTextBrush}" Style="{StaticResource ButtonIcon}" hc:IconElement.Geometry="{StaticResource DeleteFillCircleGeometry}"/>
|
||||
<Button Command="hc:ControlCommands.Close" Grid.Row="0" HorizontalAlignment="Right" Foreground="{DynamicResource PrimaryTextBrush}" Style="{StaticResource ButtonIcon}" hc:IconElement.Geometry="{StaticResource DeleteFillCircleGeometry}"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</hc:Drawer>
|
||||
@ -41,7 +41,7 @@
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Margin="10,0,0,0" Text="Header" Style="{StaticResource TextBlockTitle}" HorizontalAlignment="Left"/>
|
||||
<Button CommandTarget="{Binding}" Command="hc:ControlCommands.Close" Grid.Row="0" HorizontalAlignment="Right" Foreground="{DynamicResource PrimaryTextBrush}" Style="{StaticResource ButtonIcon}" hc:IconElement.Geometry="{StaticResource DeleteFillCircleGeometry}"/>
|
||||
<Button Command="hc:ControlCommands.Close" Grid.Row="0" HorizontalAlignment="Right" Foreground="{DynamicResource PrimaryTextBrush}" Style="{StaticResource ButtonIcon}" hc:IconElement.Geometry="{StaticResource DeleteFillCircleGeometry}"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</hc:Drawer>
|
||||
@ -53,7 +53,7 @@
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Margin="10,0,0,0" Text="Header" Style="{StaticResource TextBlockTitle}" HorizontalAlignment="Left"/>
|
||||
<Button CommandTarget="{Binding}" Command="hc:ControlCommands.Close" Grid.Row="0" HorizontalAlignment="Right" Foreground="{DynamicResource PrimaryTextBrush}" Style="{StaticResource ButtonIcon}" hc:IconElement.Geometry="{StaticResource DeleteFillCircleGeometry}"/>
|
||||
<Button Command="hc:ControlCommands.Close" Grid.Row="0" HorizontalAlignment="Right" Foreground="{DynamicResource PrimaryTextBrush}" Style="{StaticResource ButtonIcon}" hc:IconElement.Geometry="{StaticResource DeleteFillCircleGeometry}"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</hc:Drawer>
|
||||
@ -65,7 +65,7 @@
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Margin="10,0,0,0" Text="Header" Style="{StaticResource TextBlockTitle}" HorizontalAlignment="Left"/>
|
||||
<Button CommandTarget="{Binding}" Command="hc:ControlCommands.Close" Grid.Row="0" HorizontalAlignment="Right" Foreground="{DynamicResource PrimaryTextBrush}" Style="{StaticResource ButtonIcon}" hc:IconElement.Geometry="{StaticResource DeleteFillCircleGeometry}"/>
|
||||
<Button Command="hc:ControlCommands.Close" Grid.Row="0" HorizontalAlignment="Right" Foreground="{DynamicResource PrimaryTextBrush}" Style="{StaticResource ButtonIcon}" hc:IconElement.Geometry="{StaticResource DeleteFillCircleGeometry}"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</hc:Drawer>
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Markup;
|
||||
@ -37,12 +38,15 @@ namespace HandyControl.Controls
|
||||
|
||||
private Point _contentRenderTransformOrigin;
|
||||
|
||||
static Drawer()
|
||||
{
|
||||
DataContextProperty.OverrideMetadata(typeof(Drawer), new FrameworkPropertyMetadata(DataContextPropertyChanged));
|
||||
}
|
||||
|
||||
public Drawer()
|
||||
{
|
||||
Loaded += Drawer_Loaded;
|
||||
Unloaded += Drawer_Unloaded;
|
||||
|
||||
CommandBindings.Add(new CommandBinding(ControlCommands.Close, (s, e) => SetCurrentValue(IsOpenProperty, ValueBoxes.FalseBox)));
|
||||
}
|
||||
|
||||
private void Drawer_Loaded(object sender, RoutedEventArgs e)
|
||||
@ -68,6 +72,11 @@ namespace HandyControl.Controls
|
||||
}
|
||||
}
|
||||
|
||||
private static void DataContextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) =>
|
||||
((Drawer)d).OnDataContextPropertyChanged(e);
|
||||
|
||||
private void OnDataContextPropertyChanged(DependencyPropertyChangedEventArgs e) => UpdateDataContext(_animationControl, e.OldValue, e.NewValue);
|
||||
|
||||
public static readonly RoutedEvent OpenedEvent =
|
||||
EventManager.RegisterRoutedEvent("Opened", RoutingStrategy.Bubble,
|
||||
typeof(RoutedEventHandler), typeof(Drawer));
|
||||
@ -223,6 +232,9 @@ namespace HandyControl.Controls
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
_animationControl.DataContext = DataContext;
|
||||
_animationControl.CommandBindings.Clear();
|
||||
_animationControl.CommandBindings.Add(new CommandBinding(ControlCommands.Close, (s, e) => SetCurrentValue(IsOpenProperty, ValueBoxes.FalseBox)));
|
||||
panel.Children.Add(_animationControl);
|
||||
_container = new AdornerContainer(_layer)
|
||||
{
|
||||
@ -381,5 +393,14 @@ namespace HandyControl.Controls
|
||||
SetCurrentValue(IsOpenProperty, ValueBoxes.FalseBox);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateDataContext(FrameworkElement target, object oldValue, object newValue)
|
||||
{
|
||||
if (target == null || BindingOperations.GetBindingExpression(target, DataContextProperty) != null) return;
|
||||
if (ReferenceEquals(this, target.DataContext) || Equals(oldValue, target.DataContext))
|
||||
{
|
||||
target.DataContext = newValue ?? this;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user