Click here to Skip to main content
15,891,976 members
Articles / Desktop Programming / WPF

AvalonDock [2.0] Tutorial Part 1 - Adding a Tool Window

Rate me:
Please Sign up or sign in to vote.
4.97/5 (37 votes)
6 Nov 2018CPOL9 min read 291.6K   12K   125  
How to create a new tool window in AvalonDock [2.0]
namespace SimpleControls.MRU.Model
{
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Xml.Serialization;
  using System.Collections.ObjectModel;

  public class MRUList
  {
    #region constructor
    public MRUList()
    {
      this.Entries = new List<MRUEntry>();
    }

    public MRUList(MRUList copySource)
    {
      if (copySource == null) return;

      this.Entries = new List<MRUEntry>(copySource.Entries);
    }
    #endregion constructor

    internal enum Spot
    {
      First = 0,
      Last = 1
    }

    #region properties
    [XmlArray(ElementName = "Entries", Namespace = "MRUList")]
    [XmlArrayItem(ElementName = "Entry", Namespace = "MRUList")]
    public List<MRUEntry> Entries { get; set; }
    #endregion properties

    #region AddRemoveEntries
    internal bool AddEntry(MRUEntry emp,
                           MRUList.Spot addInSpot = MRUList.Spot.Last)
    {
      if(emp == null)
        return false;

      if(this.Entries == null)
        this.Entries =  new List<MRUEntry>();

      switch (addInSpot)
      {
        case Spot.First:
          this.Entries.Insert(0, new MRUEntry(emp));
          return true;

        case Spot.Last: 
          this.Entries.Add(new MRUEntry(emp));
          return true;

        default:
          throw new NotImplementedException(addInSpot.ToString());
      }
    }

    internal void RemoveEntry(Spot addInSpot)
    {
      if (this.Entries == null) return;

      if (this.Entries.Count == 0) return;

      switch (addInSpot)
      {
        case Spot.First:
          this.Entries.RemoveAt(0);
          break;
        case Spot.Last:
          this.Entries.RemoveAt(this.Entries.Count - 1);
          break;
        default:
          break;
      }
    }
    #endregion AddRemoveEntries

    #region AddRemovePinnedEntries
    internal void AddPinedEntry(MRUEntry emp)
    {
      if (emp == null)
        return;

      if (this.Entries == null)
        this.Entries = new List<MRUEntry>();

      this.Entries.Add(new MRUEntry(emp));
    }
    #endregion AddRemovePinnedEntries

    internal void RemoveMruPath(string p)
    {
      if (this.Entries != null && p != null)
        this.Entries.RemoveAll(item => p == item.PathFileName);      
    }
  }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Germany Germany
The Windows Presentation Foundation (WPF) and C# are among my favorites and so I developed Edi

and a few other projects on GitHub. I am normally an algorithms and structure type but WPF has such interesting UI sides that I cannot help myself but get into it.

https://de.linkedin.com/in/dirkbahle

Comments and Discussions