Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change BladeItem to be an Expander #1248

Merged
merged 2 commits into from
Jun 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ public partial class BladeItem
/// </summary>
public static readonly DependencyProperty CloseButtonForegroundProperty = DependencyProperty.Register(nameof(CloseButtonForeground), typeof(Brush), typeof(BladeItem), new PropertyMetadata(new SolidColorBrush(Colors.Black)));

/// <summary>
/// Identifies the <see cref="BladeItemMode"/> dependency property
/// </summary>
public static readonly DependencyProperty BladeItemModeProperty = DependencyProperty.RegisterAttached(nameof(BladeItemMode), typeof(BladeItemMode), typeof(BladeItem), new PropertyMetadata(BladeItemMode.Normal, OnBladeItemModeChanged));

/// <summary>
/// Gets or sets the foreground color of the close button
/// </summary>
Expand Down Expand Up @@ -124,36 +119,11 @@ public bool IsOpen
set { SetValue(IsOpenProperty, value); }
}

/// <summary>
/// Gets or sets a value indicating in what mode the blade should be presented, normal or small
/// </summary>
public BladeItemMode BladeItemMode
{
get { return (BladeItemMode)GetValue(BladeItemModeProperty); }
set { SetValue(BladeItemModeProperty, value); }
}

private static void IsOpenChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
{
BladeItem bladeItem = (BladeItem)dependencyObject;
bladeItem.Visibility = bladeItem.IsOpen ? Visibility.Visible : Visibility.Collapsed;
bladeItem.VisibilityChanged?.Invoke(bladeItem, bladeItem.Visibility);
}

private static void OnBladeItemModeChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
{
BladeItem bladeItem = (BladeItem)dependencyObject;

if (bladeItem.BladeItemMode == BladeItemMode.Normal)
{
VisualStateManager.GoToState(bladeItem, "Expanded", true);
bladeItem.Width = bladeItem._normalModeWidth;
}
else
{
VisualStateManager.GoToState(bladeItem, "Collapsed", true);
bladeItem.Width = double.NaN;
}
}
}
}
26 changes: 23 additions & 3 deletions Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
/// </summary>
[TemplatePart(Name = "CloseButton", Type = typeof(Button))]
[TemplatePart(Name = "EnlargeButton", Type = typeof(Button))]
public partial class BladeItem : ContentControl
public partial class BladeItem : Expander
{
private Button _closeButton;
private Button _enlargeButton;
private double _normalModeWidth;
private bool _loaded = false;

/// <summary>
/// Initializes a new instance of the <see cref="BladeItem"/> class.
Expand All @@ -42,6 +43,7 @@ public BladeItem()
/// </summary>
protected override void OnApplyTemplate()
{
_loaded = true;
base.OnApplyTemplate();

_closeButton = GetTemplateChild("CloseButton") as Button;
Expand All @@ -64,9 +66,27 @@ protected override void OnApplyTemplate()
_enlargeButton.Click += EnlargeButton_Click;
}

protected override void OnExpanded(EventArgs args)
{
base.OnExpanded(args);
if (_loaded)
{
Width = _normalModeWidth;
}
}

protected override void OnCollapsed(EventArgs args)
{
base.OnCollapsed(args);
if (_loaded)
{
Width = double.NaN;
}
}

private void OnSizeChanged(object sender, SizeChangedEventArgs sizeChangedEventArgs)
{
if (BladeItemMode == BladeItemMode.Normal)
if (IsExpanded)
{
_normalModeWidth = Width;
}
Expand All @@ -79,7 +99,7 @@ private void CloseButton_Click(object sender, RoutedEventArgs e)

private void EnlargeButton_Click(object sender, RoutedEventArgs e)
{
BladeItemMode = BladeItemMode == BladeItemMode.Normal ? BladeItemMode.Small : BladeItemMode.Normal;
IsExpanded = !IsExpanded;
}
}
}
30 changes: 0 additions & 30 deletions Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItemMode.cs

This file was deleted.

4 changes: 2 additions & 2 deletions Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private void CycleBlades()
{
for (int i = 0; i < openBlades.Count - 1; i++)
{
openBlades[i].BladeItemMode = BladeItemMode.Small;
openBlades[i].IsExpanded = false;
}
}
}
Expand Down Expand Up @@ -156,7 +156,7 @@ await Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
var lastBlade = ActiveBlades.LastOrDefault();
if (lastBlade != null && lastBlade.TitleBarVisibility == Visibility.Visible)
{
lastBlade.BladeItemMode = BladeItemMode.Normal;
lastBlade.IsExpanded = true;
}
}

Expand Down
1 change: 1 addition & 0 deletions Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
<Setter Property="BorderBrush" Value="Black" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="IsTabStop" Value="False" />
<Setter Property="IsExpanded" Value="True"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:BladeItem">
Expand Down
14 changes: 12 additions & 2 deletions Microsoft.Toolkit.Uwp.UI.Controls/Expander/Expander.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ protected override void OnApplyTemplate()
}
}

protected virtual void OnExpanded(EventArgs args)
{
Expanded?.Invoke(this, args);
}

protected virtual void OnCollapsed(EventArgs args)
{
Collapsed?.Invoke(this, args);
}

private void ExpanderToggleButtonPart_KeyDown(object sender, Windows.UI.Xaml.Input.KeyRoutedEventArgs e)
{
if (e.Key != VirtualKey.Enter)
Expand All @@ -73,13 +83,13 @@ private void ExpanderToggleButtonPart_KeyDown(object sender, Windows.UI.Xaml.Inp
private void ExpandControl()
{
VisualStateManager.GoToState(this, StateContentExpanded, true);
Expanded?.Invoke(this, EventArgs.Empty);
OnExpanded(EventArgs.Empty);
}

private void CollapseControl()
{
VisualStateManager.GoToState(this, StateContentCollapsed, true);
Collapsed?.Invoke(this, EventArgs.Empty);
OnCollapsed(EventArgs.Empty);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
<Compile Include="BladeView\BladeControl.cs" />
<Compile Include="BladeView\BladeItem.cs" />
<Compile Include="BladeView\BladeItem.Properties.cs" />
<Compile Include="BladeView\BladeItemMode.cs" />
<Compile Include="BladeView\BladeMode.cs" />
<Compile Include="BladeView\BladeView.cs" />
<Compile Include="BladeView\BladeView.Events.cs" />
Expand Down