mirror of https://github.com/AMT-Cheif/Stylet.git
Add ConductorNavigating, OnInitialActivate, and the StretchingTreeView. Not sure if the latter will stay
This commit is contained in:
parent
b2b489c791
commit
17a097c907
|
@ -0,0 +1,82 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Stylet.SlightlyInternal;
|
||||
|
||||
namespace Stylet
|
||||
{
|
||||
public partial class Conductor<T>
|
||||
{
|
||||
public partial class Collections
|
||||
{
|
||||
/// <summary>
|
||||
/// Conductor which has one active item, and a stack of previous items
|
||||
/// </summary>
|
||||
public class Navigation : ConductorBaseWithActiveItem<T>
|
||||
{
|
||||
private List<T> history = new List<T>();
|
||||
|
||||
public override void ActivateItem(T item)
|
||||
{
|
||||
if (item != null && item.Equals(this.ActiveItem))
|
||||
{
|
||||
if (this.IsActive)
|
||||
ScreenExtensions.TryActivate(this.ActiveItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.ActiveItem != null)
|
||||
this.history.Add(this.ActiveItem);
|
||||
this.ChangeActiveItem(item, false);
|
||||
}
|
||||
}
|
||||
|
||||
public override void DeactivateItem(T item)
|
||||
{
|
||||
ScreenExtensions.TryDeactivate(item);
|
||||
}
|
||||
|
||||
public void GoBack()
|
||||
{
|
||||
this.CloseItem(this.ActiveItem);
|
||||
}
|
||||
|
||||
public override async void CloseItem(T item)
|
||||
{
|
||||
if (item == null || !await this.CanCloseItem(item))
|
||||
return;
|
||||
|
||||
if (item.Equals(this.ActiveItem))
|
||||
{
|
||||
var newItem = default(T);
|
||||
if (this.history.Count > 0)
|
||||
{
|
||||
newItem = this.history.Last();
|
||||
this.history.RemoveAt(this.history.Count-1);
|
||||
}
|
||||
this.ChangeActiveItem(newItem, true);
|
||||
}
|
||||
else if (this.history.Contains(item))
|
||||
{
|
||||
this.history.Remove(item);
|
||||
}
|
||||
}
|
||||
|
||||
public override Task<bool> CanCloseAsync()
|
||||
{
|
||||
return this.CanAllItemsCloseAsync(this.history.Concat(new[] { this.ActiveItem }));
|
||||
}
|
||||
|
||||
protected override void OnClose()
|
||||
{
|
||||
// We've already been deactivated by this point
|
||||
foreach (var item in this.history)
|
||||
this.CloseAndCleanUp(item);
|
||||
this.history.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -25,6 +25,8 @@ namespace Stylet
|
|||
|
||||
public event EventHandler<ActivationEventArgs> Activated;
|
||||
|
||||
private bool hasBeenActivatedEver;
|
||||
|
||||
private bool _isActive;
|
||||
public bool IsActive
|
||||
{
|
||||
|
@ -39,6 +41,10 @@ namespace Stylet
|
|||
|
||||
this.IsActive = true;
|
||||
|
||||
if (!this.hasBeenActivatedEver)
|
||||
this.OnInitialActivate();
|
||||
this.hasBeenActivatedEver = true;
|
||||
|
||||
this.OnActivate();
|
||||
|
||||
var handler = this.Activated;
|
||||
|
@ -46,6 +52,7 @@ namespace Stylet
|
|||
handler(this, new ActivationEventArgs());
|
||||
}
|
||||
|
||||
protected virtual void OnInitialActivate() { }
|
||||
protected virtual void OnActivate() { }
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
|
||||
namespace Stylet
|
||||
{
|
||||
// http://blogs.msdn.com/b/jpricket/archive/2008/08/05/wpf-a-stretching-treeview.aspx
|
||||
public class StretchingTreeView : TreeView
|
||||
{
|
||||
protected override DependencyObject GetContainerForItemOverride()
|
||||
{
|
||||
return new StretchingTreeViewItem();
|
||||
}
|
||||
|
||||
protected override bool IsItemItsOwnContainerOverride(object item)
|
||||
{
|
||||
return item is StretchingTreeViewItem;
|
||||
}
|
||||
}
|
||||
|
||||
public class StretchingTreeViewItem : TreeViewItem
|
||||
{
|
||||
public StretchingTreeViewItem()
|
||||
{
|
||||
this.Loaded += new RoutedEventHandler(StretchingTreeViewItem_Loaded);
|
||||
}
|
||||
|
||||
private void StretchingTreeViewItem_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// The purpose of this code is to stretch the Header Content all the way accross the TreeView.
|
||||
if (this.VisualChildrenCount > 0)
|
||||
{
|
||||
Grid grid = this.GetVisualChild(0) as Grid;
|
||||
if (grid != null && grid.ColumnDefinitions.Count == 3)
|
||||
{
|
||||
// Remove the middle column which is set to Auto and let it get replaced with the
|
||||
// last column that is set to Star.
|
||||
grid.ColumnDefinitions.RemoveAt(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override DependencyObject GetContainerForItemOverride()
|
||||
{
|
||||
return new StretchingTreeViewItem();
|
||||
}
|
||||
|
||||
protected override bool IsItemItsOwnContainerOverride(object item)
|
||||
{
|
||||
return item is StretchingTreeViewItem;
|
||||
}
|
||||
|
||||
// http://stackoverflow.com/a/2957734/1086121
|
||||
public override void OnApplyTemplate()
|
||||
{
|
||||
base.OnApplyTemplate();
|
||||
|
||||
if (Template != null)
|
||||
{
|
||||
var btn = Template.FindName("Expander", this) as ToggleButton;
|
||||
if (btn != null)
|
||||
btn.VerticalAlignment = this.ToggleButtonVerticalAlignment;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public VerticalAlignment ToggleButtonVerticalAlignment
|
||||
{
|
||||
get { return (VerticalAlignment)GetValue(ToggleButtonVerticalAlignmentProperty); }
|
||||
set { SetValue(ToggleButtonVerticalAlignmentProperty, value); }
|
||||
}
|
||||
|
||||
// Using a DependencyProperty as the backing store for ToggleButtonVerticalAlignment. This enables animation, styling, binding, etc...
|
||||
public static readonly DependencyProperty ToggleButtonVerticalAlignmentProperty =
|
||||
DependencyProperty.Register("ToggleButtonVerticalAlignment", typeof(VerticalAlignment), typeof(StretchingTreeViewItem), new PropertyMetadata(VerticalAlignment.Center));
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -43,6 +43,7 @@
|
|||
<Reference Include="WindowsBase" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ConductorNavigating.cs" />
|
||||
<Compile Include="SlightlyInternal\ConductorUtilities.cs" />
|
||||
<Compile Include="INotifyPropertyChangedDispatcher.cs" />
|
||||
<Compile Include="Xaml\ActionExtension.cs" />
|
||||
|
@ -80,6 +81,7 @@
|
|||
<Compile Include="View.cs" />
|
||||
<Compile Include="ViewManager.cs" />
|
||||
<Compile Include="WindowManager.cs" />
|
||||
<Compile Include="StretchingTreeView.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Include="Xaml\StyletResourceDictionary.xaml">
|
||||
|
|
|
@ -65,7 +65,7 @@ namespace Stylet
|
|||
throw new ArgumentException(String.Format("Unable to find method {0} on {1}", this.methodName, newTargetType.Name));
|
||||
|
||||
var methodParameters = targetMethodInfo.GetParameters();
|
||||
if (methodParameters.Length > 1 || (methodParameters.Length == 1 && !typeof(RoutedEventArgs).IsAssignableFrom(methodParameters[0].ParameterType)))
|
||||
if (methodParameters.Length > 1 || (methodParameters.Length == 1 && !methodParameters[0].ParameterType.IsAssignableFrom(typeof(RoutedEventArgs))))
|
||||
throw new ArgumentException(String.Format("Method {0} on {1} must have zero parameters, or a single parameter accepting a RoutedEventArgs", this.methodName, newTargetType.Name));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue