optimized drawer
This commit is contained in:
1 parent
27c9458130
commit
3dad11526c
3 files changed
+28
-7
No files matched your search
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
|
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
|
||||||
<metadata>
|
<metadata>
|
||||||
<id>HandyControl</id>
|
<id>HandyControl</id>
|
||||||
<version>2.5.0</version>
|
<version>2.5.0.2</version>
|
||||||
<title>HandyOrg</title>
|
<title>HandyOrg</title>
|
||||||
<authors>HandyOrg</authors>
|
<authors>HandyOrg</authors>
|
||||||
<owners>HandyOrg</owners>
|
<owners>HandyOrg</owners>
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
<RowDefinition/>
|
<RowDefinition/>
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<TextBlock Margin="10,0,0,0" Text="Header" Style="{StaticResource TextBlockTitle}" HorizontalAlignment="Left"/>
|
<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>
|
</Grid>
|
||||||
</Border>
|
</Border>
|
||||||
</hc:Drawer>
|
</hc:Drawer>
|
||||||
@@ -41,7 +41,7 @@
|
|||||||
<RowDefinition/>
|
<RowDefinition/>
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<TextBlock Margin="10,0,0,0" Text="Header" Style="{StaticResource TextBlockTitle}" HorizontalAlignment="Left"/>
|
<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>
|
</Grid>
|
||||||
</Border>
|
</Border>
|
||||||
</hc:Drawer>
|
</hc:Drawer>
|
||||||
@@ -53,7 +53,7 @@
|
|||||||
<RowDefinition/>
|
<RowDefinition/>
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<TextBlock Margin="10,0,0,0" Text="Header" Style="{StaticResource TextBlockTitle}" HorizontalAlignment="Left"/>
|
<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>
|
</Grid>
|
||||||
</Border>
|
</Border>
|
||||||
</hc:Drawer>
|
</hc:Drawer>
|
||||||
@@ -65,7 +65,7 @@
|
|||||||
<RowDefinition/>
|
<RowDefinition/>
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<TextBlock Margin="10,0,0,0" Text="Header" Style="{StaticResource TextBlockTitle}" HorizontalAlignment="Left"/>
|
<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>
|
</Grid>
|
||||||
</Border>
|
</Border>
|
||||||
</hc:Drawer>
|
</hc:Drawer>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Data;
|
||||||
using System.Windows.Documents;
|
using System.Windows.Documents;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Markup;
|
using System.Windows.Markup;
|
||||||
@@ -37,12 +38,15 @@ namespace HandyControl.Controls
|
|||||||
|
|
||||||
private Point _contentRenderTransformOrigin;
|
private Point _contentRenderTransformOrigin;
|
||||||
|
|
||||||
|
static Drawer()
|
||||||
|
{
|
||||||
|
DataContextProperty.OverrideMetadata(typeof(Drawer), new FrameworkPropertyMetadata(DataContextPropertyChanged));
|
||||||
|
}
|
||||||
|
|
||||||
public Drawer()
|
public Drawer()
|
||||||
{
|
{
|
||||||
Loaded += Drawer_Loaded;
|
Loaded += Drawer_Loaded;
|
||||||
Unloaded += Drawer_Unloaded;
|
Unloaded += Drawer_Unloaded;
|
||||||
|
|
||||||
CommandBindings.Add(new CommandBinding(ControlCommands.Close, (s, e) => SetCurrentValue(IsOpenProperty, ValueBoxes.FalseBox)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Drawer_Loaded(object sender, RoutedEventArgs e)
|
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 =
|
public static readonly RoutedEvent OpenedEvent =
|
||||||
EventManager.RegisterRoutedEvent("Opened", RoutingStrategy.Bubble,
|
EventManager.RegisterRoutedEvent("Opened", RoutingStrategy.Bubble,
|
||||||
typeof(RoutedEventHandler), typeof(Drawer));
|
typeof(RoutedEventHandler), typeof(Drawer));
|
||||||
@@ -223,6 +232,9 @@ namespace HandyControl.Controls
|
|||||||
throw new ArgumentOutOfRangeException();
|
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);
|
panel.Children.Add(_animationControl);
|
||||||
_container = new AdornerContainer(_layer)
|
_container = new AdornerContainer(_layer)
|
||||||
{
|
{
|
||||||
@@ -381,5 +393,14 @@ namespace HandyControl.Controls
|
|||||||
SetCurrentValue(IsOpenProperty, ValueBoxes.FalseBox);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user