| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240 |
- /*************************************************************************************
- Extended WPF Toolkit
- Copyright (C) 2007-2013 Xceed Software Inc.
- This program is provided to you under the terms of the Microsoft Public
- License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
- For more features, controls, and fast professional support,
- pick up the Plus Edition at http://xceed.com/wpf_toolkit
- Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
- ***********************************************************************************/
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Collections.Specialized;
- using System.ComponentModel;
- using System.Diagnostics;
- using System.Linq;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Input;
- using System.Windows.Interop;
- using System.Windows.Markup;
- using System.Windows.Threading;
- using Xceed.Wpf.AvalonDock.Controls;
- using Xceed.Wpf.AvalonDock.Layout;
- using Xceed.Wpf.AvalonDock.Themes;
- namespace Xceed.Wpf.AvalonDock
- {
- [ContentProperty("Layout")]
- [TemplatePart(Name = "PART_AutoHideArea")]
- public class DockingManager : Control, IOverlayWindowHost//, ILogicalChildrenContainer
- {
- private ResourceDictionary currentThemeResourceDictionary; // = null
- static DockingManager()
- {
- DefaultStyleKeyProperty.OverrideMetadata(typeof(DockingManager), new FrameworkPropertyMetadata(typeof(DockingManager)));
- FocusableProperty.OverrideMetadata(typeof(DockingManager), new FrameworkPropertyMetadata(false));
- HwndSource.DefaultAcquireHwndFocusInMenuMode = false;
- }
- public DockingManager()
- {
- Layout = new LayoutRoot() { RootPanel = new LayoutPanel(new LayoutDocumentPaneGroup(new LayoutDocumentPane())) };
- this.Loaded += new RoutedEventHandler(DockingManager_Loaded);
- this.Unloaded += new RoutedEventHandler(DockingManager_Unloaded);
- }
- #region Layout
- /// <summary>
- /// Layout Dependency Property
- /// </summary>
- public static readonly DependencyProperty LayoutProperty =
- DependencyProperty.Register("Layout", typeof(LayoutRoot), typeof(DockingManager),
- new FrameworkPropertyMetadata(null,
- new PropertyChangedCallback(OnLayoutChanged),
- new CoerceValueCallback(CoerceLayoutValue)));
- /// <summary>
- /// Gets or sets the Layout property. This dependency property
- /// indicates layout tree.
- /// </summary>
- public LayoutRoot Layout
- {
- get { return (LayoutRoot)GetValue(LayoutProperty); }
- set { SetValue(LayoutProperty, value); }
- }
- /// <summary>
- /// Handles changes to the Layout property.
- /// </summary>
- private static void OnLayoutChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((DockingManager)d).OnLayoutChanged(e.OldValue as LayoutRoot, e.NewValue as LayoutRoot);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the <see cref="DockingManager.Layout"/> property.
- /// </summary>
- protected virtual void OnLayoutChanged(LayoutRoot oldLayout, LayoutRoot newLayout)
- {
- if (oldLayout != null)
- {
- oldLayout.PropertyChanged -= new PropertyChangedEventHandler(OnLayoutRootPropertyChanged);
- oldLayout.Updated -= new EventHandler(OnLayoutRootUpdated);
- }
- foreach (var fwc in _fwList.ToArray())
- {
- fwc.KeepContentVisibleOnClose = true;
- fwc.InternalClose();
- }
- _fwList.Clear();
- DetachDocumentsSource(oldLayout, DocumentsSource);
- DetachAnchorablesSource(oldLayout, AnchorablesSource);
- if (oldLayout != null &&
- oldLayout.Manager == this)
- oldLayout.Manager = null;
- ClearLogicalChildrenList();
- DetachLayoutItems();
- Layout.Manager = this;
- AttachLayoutItems();
- AttachDocumentsSource(newLayout, DocumentsSource);
- AttachAnchorablesSource(newLayout, AnchorablesSource);
- if (IsLoaded)
- {
- LayoutRootPanel = CreateUIElementForModel(Layout.RootPanel) as LayoutPanelControl;
- LeftSidePanel = CreateUIElementForModel(Layout.LeftSide) as LayoutAnchorSideControl;
- TopSidePanel = CreateUIElementForModel(Layout.TopSide) as LayoutAnchorSideControl;
- RightSidePanel = CreateUIElementForModel(Layout.RightSide) as LayoutAnchorSideControl;
- BottomSidePanel = CreateUIElementForModel(Layout.BottomSide) as LayoutAnchorSideControl;
- foreach (var fw in Layout.FloatingWindows.ToArray())
- {
- if (fw.IsValid)
- _fwList.Add(CreateUIElementForModel(fw) as LayoutFloatingWindowControl);
- }
- foreach (var fw in _fwList)
- {
- //fw.Owner = Window.GetWindow(this);
- //fw.SetParentToMainWindowOf(this);
- }
- }
- if (newLayout != null)
- {
- newLayout.PropertyChanged += new PropertyChangedEventHandler(OnLayoutRootPropertyChanged);
- newLayout.Updated += new EventHandler(OnLayoutRootUpdated);
- }
- if (LayoutChanged != null)
- LayoutChanged(this, EventArgs.Empty);
- //if (Layout != null)
- // Layout.CollectGarbage();
- CommandManager.InvalidateRequerySuggested();
- }
- DispatcherOperation _setFocusAsyncOperation = null;
- void OnLayoutRootPropertyChanged(object sender, PropertyChangedEventArgs e)
- {
- if (e.PropertyName == "RootPanel")
- {
- if (IsInitialized)
- {
- var layoutRootPanel = CreateUIElementForModel(Layout.RootPanel) as LayoutPanelControl;
- LayoutRootPanel = layoutRootPanel;
- }
- }
- else if (e.PropertyName == "ActiveContent")
- {
- if (Layout.ActiveContent != null)
- {
- //Debug.WriteLine(new StackTrace().ToString());
- //set focus on active element only after a layout pass is completed
- //it's possible that it is not yet visible in the visual tree
- if (_setFocusAsyncOperation == null)
- {
- _setFocusAsyncOperation = Dispatcher.BeginInvoke(new Action(() =>
- {
- if (Layout.ActiveContent != null)
- FocusElementManager.SetFocusOnLastElement(Layout.ActiveContent);
- _setFocusAsyncOperation = null;
- }), DispatcherPriority.Background);
- }
- }
- if (!_insideInternalSetActiveContent)
- ActiveContent = Layout.ActiveContent != null ?
- Layout.ActiveContent.Content : null;
- }
- }
- void OnLayoutRootUpdated(object sender, EventArgs e)
- {
- CommandManager.InvalidateRequerySuggested();
- }
- /// <summary>
- /// Event fired when <see cref="DockingManager.Layout"/> property changes
- /// </summary>
- public event EventHandler LayoutChanged;
- /// <summary>
- /// Coerces the <see cref="DockingManager.Layout"/> value.
- /// </summary>
- private static object CoerceLayoutValue(DependencyObject d, object value)
- {
- if (value == null)
- return new LayoutRoot() { RootPanel = new LayoutPanel(new LayoutDocumentPaneGroup(new LayoutDocumentPane())) };
- ((DockingManager)d).OnLayoutChanging(value as LayoutRoot);
- return value;
- }
- /// <summary>
- /// Event fired when <see cref="DockingManager.Layout"/> property is about to be changed
- /// </summary>
- public event EventHandler LayoutChanging;
- void OnLayoutChanging(LayoutRoot newLayout)
- {
- if (LayoutChanging != null)
- LayoutChanging(this, EventArgs.Empty);
- }
- #region LayoutUpdateStrategy
- /// <summary>
- /// LayoutUpdateStrategy Dependency Property
- /// </summary>
- public static readonly DependencyProperty LayoutUpdateStrategyProperty =
- DependencyProperty.Register("LayoutUpdateStrategy", typeof(ILayoutUpdateStrategy), typeof(DockingManager),
- new FrameworkPropertyMetadata((ILayoutUpdateStrategy)null));
- /// <summary>
- /// Gets or sets the LayoutUpdateStrategy property. This dependency property
- /// indicates the strategy class to call when AvalonDock needs to positionate a LayoutAnchorable inside an existing layout.
- /// </summary>
- /// <remarks>Sometimes it's impossible to automatically insert an anchorable in the layout without specifing the target parent pane.
- /// Set this property to an object that will be asked to insert the anchorable to the desidered position.</remarks>
- public ILayoutUpdateStrategy LayoutUpdateStrategy
- {
- get { return (ILayoutUpdateStrategy)GetValue(LayoutUpdateStrategyProperty); }
- set { SetValue(LayoutUpdateStrategyProperty, value); }
- }
- #endregion
- #endregion
- public override void OnApplyTemplate()
- {
- base.OnApplyTemplate();
- SetupAutoHideWindow();
- }
- protected override void OnInitialized(EventArgs e)
- {
- base.OnInitialized(e);
- }
- void DockingManager_Loaded(object sender, RoutedEventArgs e)
- {
- if (!DesignerProperties.GetIsInDesignMode(this))
- {
- if (Layout.Manager == this)
- {
- LayoutRootPanel = CreateUIElementForModel(Layout.RootPanel) as LayoutPanelControl;
- LeftSidePanel = CreateUIElementForModel(Layout.LeftSide) as LayoutAnchorSideControl;
- TopSidePanel = CreateUIElementForModel(Layout.TopSide) as LayoutAnchorSideControl;
- RightSidePanel = CreateUIElementForModel(Layout.RightSide) as LayoutAnchorSideControl;
- BottomSidePanel = CreateUIElementForModel(Layout.BottomSide) as LayoutAnchorSideControl;
- }
- //load windows not already loaded!
- foreach (var fw in Layout.FloatingWindows.Where(fw => !_fwList.Any(fwc => fwc.Model == fw)))
- _fwList.Add(CreateUIElementForModel(fw) as LayoutFloatingWindowControl);
- //create the overlaywindow if it's possible
- if (IsVisible)
- CreateOverlayWindow();
- FocusElementManager.SetupFocusManagement(this);
- }
- }
- void DockingManager_Unloaded(object sender, RoutedEventArgs e)
- {
- if (!DesignerProperties.GetIsInDesignMode(this))
- {
- if (_autoHideWindowManager != null)
- {
- _autoHideWindowManager.HideAutoWindow();
- }
- foreach (var fw in _fwList.ToArray())
- {
- //fw.Owner = null;
- fw.SetParentWindowToNull();
- fw.KeepContentVisibleOnClose = true;
- fw.Close();
- }
- DestroyOverlayWindow();
- FocusElementManager.FinalizeFocusManagement(this);
- }
- }
- internal UIElement CreateUIElementForModel(ILayoutElement model)
- {
- if (model is LayoutPanel)
- return new LayoutPanelControl(model as LayoutPanel);
- if (model is LayoutAnchorablePaneGroup)
- return new LayoutAnchorablePaneGroupControl(model as LayoutAnchorablePaneGroup);
- if (model is LayoutDocumentPaneGroup)
- return new LayoutDocumentPaneGroupControl(model as LayoutDocumentPaneGroup);
- if (model is LayoutAnchorSide)
- {
- var templateModelView = new LayoutAnchorSideControl(model as LayoutAnchorSide);
- templateModelView.SetBinding(LayoutAnchorSideControl.TemplateProperty, new Binding("AnchorSideTemplate") { Source = this });
- return templateModelView;
- }
- if (model is LayoutAnchorGroup)
- {
- var templateModelView = new LayoutAnchorGroupControl(model as LayoutAnchorGroup);
- templateModelView.SetBinding(LayoutAnchorGroupControl.TemplateProperty, new Binding("AnchorGroupTemplate") { Source = this });
- return templateModelView;
- }
- if (model is LayoutDocumentPane)
- {
- var templateModelView = new LayoutDocumentPaneControl(model as LayoutDocumentPane);
- templateModelView.SetBinding(LayoutDocumentPaneControl.StyleProperty, new Binding("DocumentPaneControlStyle") { Source = this });
- return templateModelView;
- }
- if (model is LayoutAnchorablePane)
- {
- var templateModelView = new LayoutAnchorablePaneControl(model as LayoutAnchorablePane);
- templateModelView.SetBinding(LayoutAnchorablePaneControl.StyleProperty, new Binding("AnchorablePaneControlStyle") { Source = this });
- return templateModelView;
- }
- if (model is LayoutAnchorableFloatingWindow)
- {
- if (DesignerProperties.GetIsInDesignMode(this))
- return null;
- var modelFW = model as LayoutAnchorableFloatingWindow;
- var newFW = new LayoutAnchorableFloatingWindowControl(modelFW)
- {
- //Owner = Window.GetWindow(this)
- };
- newFW.SetParentToMainWindowOf(this);
- var paneForExtensions = modelFW.RootPanel.Children.OfType<LayoutAnchorablePane>().FirstOrDefault();
- if (paneForExtensions != null)
- {
- //ensure that floating window position is inside current (or nearest) monitor
- paneForExtensions.KeepInsideNearestMonitor();
- newFW.Left = paneForExtensions.FloatingLeft;
- newFW.Top = paneForExtensions.FloatingTop;
- newFW.Width = paneForExtensions.FloatingWidth;
- newFW.Height = paneForExtensions.FloatingHeight;
- }
- newFW.ShowInTaskbar = false;
- newFW.Show();
- // Do not set the WindowState before showing or it will be lost
- if (paneForExtensions != null && paneForExtensions.IsMaximized)
- {
- newFW.WindowState = WindowState.Maximized;
- }
- return newFW;
- }
- if (model is LayoutDocumentFloatingWindow)
- {
- if (DesignerProperties.GetIsInDesignMode(this))
- return null;
- var modelFW = model as LayoutDocumentFloatingWindow;
- var newFW = new LayoutDocumentFloatingWindowControl(modelFW)
- {
- //Owner = Window.GetWindow(this)
- };
- newFW.SetParentToMainWindowOf(this);
- var paneForExtensions = modelFW.RootDocument;
- if (paneForExtensions != null)
- {
- //ensure that floating window position is inside current (or nearest) monitor
- paneForExtensions.KeepInsideNearestMonitor();
- newFW.Left = paneForExtensions.FloatingLeft;
- newFW.Top = paneForExtensions.FloatingTop;
- newFW.Width = paneForExtensions.FloatingWidth;
- newFW.Height = paneForExtensions.FloatingHeight;
- }
- newFW.ShowInTaskbar = false;
- newFW.Show();
- // Do not set the WindowState before showing or it will be lost
- if (paneForExtensions != null && paneForExtensions.IsMaximized)
- {
- newFW.WindowState = WindowState.Maximized;
- }
- return newFW;
- }
- if (model is LayoutDocument)
- {
- var templateModelView = new LayoutDocumentControl() { Model = model as LayoutDocument };
- return templateModelView;
- }
- return null;
- }
- #region DocumentPaneTemplate
- /// <summary>
- /// DocumentPaneTemplate Dependency Property
- /// </summary>
- public static readonly DependencyProperty DocumentPaneTemplateProperty =
- DependencyProperty.Register("DocumentPaneTemplate", typeof(ControlTemplate), typeof(DockingManager),
- new FrameworkPropertyMetadata((ControlTemplate)null,
- new PropertyChangedCallback(OnDocumentPaneTemplateChanged)));
- /// <summary>
- /// Gets or sets the DocumentPaneDataTemplate property. This dependency property
- /// indicates .
- /// </summary>
- public ControlTemplate DocumentPaneTemplate
- {
- get { return (ControlTemplate)GetValue(DocumentPaneTemplateProperty); }
- set { SetValue(DocumentPaneTemplateProperty, value); }
- }
- /// <summary>
- /// Handles changes to the DocumentPaneTemplate property.
- /// </summary>
- private static void OnDocumentPaneTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((DockingManager)d).OnDocumentPaneTemplateChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the DocumentPaneTemplate property.
- /// </summary>
- protected virtual void OnDocumentPaneTemplateChanged(DependencyPropertyChangedEventArgs e)
- {
- }
- #endregion
- #region AnchorablePaneTemplate
- /// <summary>
- /// AnchorablePaneTemplate Dependency Property
- /// </summary>
- public static readonly DependencyProperty AnchorablePaneTemplateProperty =
- DependencyProperty.Register("AnchorablePaneTemplate", typeof(ControlTemplate), typeof(DockingManager),
- new FrameworkPropertyMetadata((ControlTemplate)null,
- new PropertyChangedCallback(OnAnchorablePaneTemplateChanged)));
- /// <summary>
- /// Gets or sets the AnchorablePaneTemplate property. This dependency property
- /// indicates ....
- /// </summary>
- public ControlTemplate AnchorablePaneTemplate
- {
- get { return (ControlTemplate)GetValue(AnchorablePaneTemplateProperty); }
- set { SetValue(AnchorablePaneTemplateProperty, value); }
- }
- /// <summary>
- /// Handles changes to the AnchorablePaneDataTemplate property.
- /// </summary>
- private static void OnAnchorablePaneTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((DockingManager)d).OnAnchorablePaneTemplateChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the AnchorablePaneDataTemplate property.
- /// </summary>
- protected virtual void OnAnchorablePaneTemplateChanged(DependencyPropertyChangedEventArgs e)
- {
- }
- #endregion
- #region AnchorSideTemplate
- /// <summary>
- /// AnchorSideTemplate Dependency Property
- /// </summary>
- public static readonly DependencyProperty AnchorSideTemplateProperty =
- DependencyProperty.Register("AnchorSideTemplate", typeof(ControlTemplate), typeof(DockingManager),
- new FrameworkPropertyMetadata((ControlTemplate)null));
- /// <summary>
- /// Gets or sets the AnchorSideTemplate property. This dependency property
- /// indicates ....
- /// </summary>
- public ControlTemplate AnchorSideTemplate
- {
- get { return (ControlTemplate)GetValue(AnchorSideTemplateProperty); }
- set { SetValue(AnchorSideTemplateProperty, value); }
- }
- #endregion
- #region AnchorGroupTemplate
- /// <summary>
- /// AnchorGroupTemplate Dependency Property
- /// </summary>
- public static readonly DependencyProperty AnchorGroupTemplateProperty =
- DependencyProperty.Register("AnchorGroupTemplate", typeof(ControlTemplate), typeof(DockingManager),
- new FrameworkPropertyMetadata((ControlTemplate)null));
- /// <summary>
- /// Gets or sets the AnchorGroupTemplate property. This dependency property
- /// indicates the template used to render the AnchorGroup control.
- /// </summary>
- public ControlTemplate AnchorGroupTemplate
- {
- get { return (ControlTemplate)GetValue(AnchorGroupTemplateProperty); }
- set { SetValue(AnchorGroupTemplateProperty, value); }
- }
- #endregion
- #region AnchorTemplate
- /// <summary>
- /// AnchorTemplate Dependency Property
- /// </summary>
- public static readonly DependencyProperty AnchorTemplateProperty =
- DependencyProperty.Register("AnchorTemplate", typeof(ControlTemplate), typeof(DockingManager),
- new FrameworkPropertyMetadata((ControlTemplate)null));
- /// <summary>
- /// Gets or sets the AnchorTemplate property. This dependency property
- /// indicates ....
- /// </summary>
- public ControlTemplate AnchorTemplate
- {
- get { return (ControlTemplate)GetValue(AnchorTemplateProperty); }
- set { SetValue(AnchorTemplateProperty, value); }
- }
- #endregion
- #region DocumentPaneControlStyle
- /// <summary>
- /// DocumentPaneControlStyle Dependency Property
- /// </summary>
- public static readonly DependencyProperty DocumentPaneControlStyleProperty =
- DependencyProperty.Register("DocumentPaneControlStyle", typeof(Style), typeof(DockingManager),
- new FrameworkPropertyMetadata((Style)null,
- new PropertyChangedCallback(OnDocumentPaneControlStyleChanged)));
- /// <summary>
- /// Gets or sets the DocumentPaneControlStyle property. This dependency property
- /// indicates ....
- /// </summary>
- public Style DocumentPaneControlStyle
- {
- get { return (Style)GetValue(DocumentPaneControlStyleProperty); }
- set { SetValue(DocumentPaneControlStyleProperty, value); }
- }
- /// <summary>
- /// Handles changes to the DocumentPaneControlStyle property.
- /// </summary>
- private static void OnDocumentPaneControlStyleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((DockingManager)d).OnDocumentPaneControlStyleChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the DocumentPaneControlStyle property.
- /// </summary>
- protected virtual void OnDocumentPaneControlStyleChanged(DependencyPropertyChangedEventArgs e)
- {
- }
- #endregion
- #region AnchorablePaneControlStyle
- /// <summary>
- /// AnchorablePaneControlStyle Dependency Property
- /// </summary>
- public static readonly DependencyProperty AnchorablePaneControlStyleProperty =
- DependencyProperty.Register("AnchorablePaneControlStyle", typeof(Style), typeof(DockingManager),
- new FrameworkPropertyMetadata((Style)null,
- new PropertyChangedCallback(OnAnchorablePaneControlStyleChanged)));
- /// <summary>
- /// Gets or sets the AnchorablePaneControlStyle property. This dependency property
- /// indicates the style to apply to AnchorablePaneControl.
- /// </summary>
- public Style AnchorablePaneControlStyle
- {
- get { return (Style)GetValue(AnchorablePaneControlStyleProperty); }
- set { SetValue(AnchorablePaneControlStyleProperty, value); }
- }
- /// <summary>
- /// Handles changes to the AnchorablePaneControlStyle property.
- /// </summary>
- private static void OnAnchorablePaneControlStyleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((DockingManager)d).OnAnchorablePaneControlStyleChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the AnchorablePaneControlStyle property.
- /// </summary>
- protected virtual void OnAnchorablePaneControlStyleChanged(DependencyPropertyChangedEventArgs e)
- {
- }
- #endregion
- #region DocumentHeaderTemplate
- /// <summary>
- /// DocumentHeaderTemplate Dependency Property
- /// </summary>
- public static readonly DependencyProperty DocumentHeaderTemplateProperty =
- DependencyProperty.Register("DocumentHeaderTemplate", typeof(DataTemplate), typeof(DockingManager),
- new FrameworkPropertyMetadata((DataTemplate)null,
- new PropertyChangedCallback(OnDocumentHeaderTemplateChanged),
- new CoerceValueCallback(CoerceDocumentHeaderTemplateValue)));
- /// <summary>
- /// Gets or sets the DocumentHeaderTemplate property. This dependency property
- /// indicates data template to use for document header.
- /// </summary>
- public DataTemplate DocumentHeaderTemplate
- {
- get { return (DataTemplate)GetValue(DocumentHeaderTemplateProperty); }
- set { SetValue(DocumentHeaderTemplateProperty, value); }
- }
- /// <summary>
- /// Handles changes to the DocumentHeaderTemplate property.
- /// </summary>
- private static void OnDocumentHeaderTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((DockingManager)d).OnDocumentHeaderTemplateChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the DocumentHeaderTemplate property.
- /// </summary>
- protected virtual void OnDocumentHeaderTemplateChanged(DependencyPropertyChangedEventArgs e)
- {
- }
- /// <summary>
- /// Coerces the DocumentHeaderTemplate value.
- /// </summary>
- private static object CoerceDocumentHeaderTemplateValue(DependencyObject d, object value)
- {
- if (value != null &&
- d.GetValue(DocumentHeaderTemplateSelectorProperty) != null)
- return null;
- return value;
- }
- #endregion
- #region DocumentHeaderTemplateSelector
- /// <summary>
- /// DocumentHeaderTemplateSelector Dependency Property
- /// </summary>
- public static readonly DependencyProperty DocumentHeaderTemplateSelectorProperty =
- DependencyProperty.Register("DocumentHeaderTemplateSelector", typeof(DataTemplateSelector), typeof(DockingManager),
- new FrameworkPropertyMetadata((DataTemplateSelector)null,
- new PropertyChangedCallback(OnDocumentHeaderTemplateSelectorChanged),
- new CoerceValueCallback(CoerceDocumentHeaderTemplateSelectorValue)));
- /// <summary>
- /// Gets or sets the DocumentHeaderTemplateSelector property. This dependency property
- /// indicates the template selector that is used when selcting the data template for the header.
- /// </summary>
- public DataTemplateSelector DocumentHeaderTemplateSelector
- {
- get { return (DataTemplateSelector)GetValue(DocumentHeaderTemplateSelectorProperty); }
- set { SetValue(DocumentHeaderTemplateSelectorProperty, value); }
- }
- /// <summary>
- /// Handles changes to the DocumentHeaderTemplateSelector property.
- /// </summary>
- private static void OnDocumentHeaderTemplateSelectorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((DockingManager)d).OnDocumentHeaderTemplateSelectorChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the DocumentHeaderTemplateSelector property.
- /// </summary>
- protected virtual void OnDocumentHeaderTemplateSelectorChanged(DependencyPropertyChangedEventArgs e)
- {
- if (e.NewValue != null &&
- DocumentHeaderTemplate != null)
- DocumentHeaderTemplate = null;
- if (DocumentPaneMenuItemHeaderTemplateSelector == null)
- DocumentPaneMenuItemHeaderTemplateSelector = DocumentHeaderTemplateSelector;
- }
- /// <summary>
- /// Coerces the DocumentHeaderTemplateSelector value.
- /// </summary>
- private static object CoerceDocumentHeaderTemplateSelectorValue(DependencyObject d, object value)
- {
- return value;
- }
- #endregion
- #region DocumentTitleTemplate
- /// <summary>
- /// DocumentTitleTemplate Dependency Property
- /// </summary>
- public static readonly DependencyProperty DocumentTitleTemplateProperty =
- DependencyProperty.Register("DocumentTitleTemplate", typeof(DataTemplate), typeof(DockingManager),
- new FrameworkPropertyMetadata((DataTemplate)null,
- new PropertyChangedCallback(OnDocumentTitleTemplateChanged),
- new CoerceValueCallback(CoerceDocumentTitleTemplateValue)));
- /// <summary>
- /// Gets or sets the DocumentTitleTemplate property. This dependency property
- /// indicates the datatemplate to use when creating the title for a document.
- /// </summary>
- public DataTemplate DocumentTitleTemplate
- {
- get { return (DataTemplate)GetValue(DocumentTitleTemplateProperty); }
- set { SetValue(DocumentTitleTemplateProperty, value); }
- }
- /// <summary>
- /// Handles changes to the DocumentTitleTemplate property.
- /// </summary>
- private static void OnDocumentTitleTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((DockingManager)d).OnDocumentTitleTemplateChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the DocumentTitleTemplate property.
- /// </summary>
- protected virtual void OnDocumentTitleTemplateChanged(DependencyPropertyChangedEventArgs e)
- {
- }
- /// <summary>
- /// Coerces the DocumentTitleTemplate value.
- /// </summary>
- private static object CoerceDocumentTitleTemplateValue(DependencyObject d, object value)
- {
- if (value != null &&
- d.GetValue(DocumentTitleTemplateSelectorProperty) != null)
- return null;
- return value;
- }
- #endregion
- #region DocumentTitleTemplateSelector
- /// <summary>
- /// DocumentTitleTemplateSelector Dependency Property
- /// </summary>
- public static readonly DependencyProperty DocumentTitleTemplateSelectorProperty =
- DependencyProperty.Register("DocumentTitleTemplateSelector", typeof(DataTemplateSelector), typeof(DockingManager),
- new FrameworkPropertyMetadata((DataTemplateSelector)null,
- new PropertyChangedCallback(OnDocumentTitleTemplateSelectorChanged),
- new CoerceValueCallback(CoerceDocumentTitleTemplateSelectorValue)));
- /// <summary>
- /// Gets or sets the DocumentTitleTemplateSelector property. This dependency property
- /// indicates the data template selector to use when creating the data template for the title.
- /// </summary>
- public DataTemplateSelector DocumentTitleTemplateSelector
- {
- get { return (DataTemplateSelector)GetValue(DocumentTitleTemplateSelectorProperty); }
- set { SetValue(DocumentTitleTemplateSelectorProperty, value); }
- }
- /// <summary>
- /// Handles changes to the DocumentTitleTemplateSelector property.
- /// </summary>
- private static void OnDocumentTitleTemplateSelectorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((DockingManager)d).OnDocumentTitleTemplateSelectorChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the DocumentTitleTemplateSelector property.
- /// </summary>
- protected virtual void OnDocumentTitleTemplateSelectorChanged(DependencyPropertyChangedEventArgs e)
- {
- if (e.NewValue != null)
- DocumentTitleTemplate = null;
- }
- /// <summary>
- /// Coerces the DocumentTitleTemplateSelector value.
- /// </summary>
- private static object CoerceDocumentTitleTemplateSelectorValue(DependencyObject d, object value)
- {
- return value;
- }
- #endregion
- #region AnchorableTitleTemplate
- /// <summary>
- /// AnchorableTitleTemplate Dependency Property
- /// </summary>
- public static readonly DependencyProperty AnchorableTitleTemplateProperty =
- DependencyProperty.Register("AnchorableTitleTemplate", typeof(DataTemplate), typeof(DockingManager),
- new FrameworkPropertyMetadata((DataTemplate)null,
- new PropertyChangedCallback(OnAnchorableTitleTemplateChanged),
- new CoerceValueCallback(CoerceAnchorableTitleTemplateValue)));
- /// <summary>
- /// Gets or sets the AnchorableTitleTemplate property. This dependency property
- /// indicates the data template to use for anchorables title.
- /// </summary>
- public DataTemplate AnchorableTitleTemplate
- {
- get { return (DataTemplate)GetValue(AnchorableTitleTemplateProperty); }
- set { SetValue(AnchorableTitleTemplateProperty, value); }
- }
- /// <summary>
- /// Handles changes to the AnchorableTitleTemplate property.
- /// </summary>
- private static void OnAnchorableTitleTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((DockingManager)d).OnAnchorableTitleTemplateChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the AnchorableTitleTemplate property.
- /// </summary>
- protected virtual void OnAnchorableTitleTemplateChanged(DependencyPropertyChangedEventArgs e)
- {
- }
- /// <summary>
- /// Coerces the AnchorableTitleTemplate value.
- /// </summary>
- private static object CoerceAnchorableTitleTemplateValue(DependencyObject d, object value)
- {
- if (value != null &&
- d.GetValue(AnchorableTitleTemplateSelectorProperty) != null)
- return null;
- return value;
- }
- #endregion
- #region AnchorableTitleTemplateSelector
- /// <summary>
- /// AnchorableTitleTemplateSelector Dependency Property
- /// </summary>
- public static readonly DependencyProperty AnchorableTitleTemplateSelectorProperty =
- DependencyProperty.Register("AnchorableTitleTemplateSelector", typeof(DataTemplateSelector), typeof(DockingManager),
- new FrameworkPropertyMetadata((DataTemplateSelector)null,
- new PropertyChangedCallback(OnAnchorableTitleTemplateSelectorChanged)));
- /// <summary>
- /// Gets or sets the AnchorableTitleTemplateSelector property. This dependency property
- /// indicates selctor to use when selecting data template for the title of anchorables.
- /// </summary>
- public DataTemplateSelector AnchorableTitleTemplateSelector
- {
- get { return (DataTemplateSelector)GetValue(AnchorableTitleTemplateSelectorProperty); }
- set { SetValue(AnchorableTitleTemplateSelectorProperty, value); }
- }
- /// <summary>
- /// Handles changes to the AnchorableTitleTemplateSelector property.
- /// </summary>
- private static void OnAnchorableTitleTemplateSelectorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((DockingManager)d).OnAnchorableTitleTemplateSelectorChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the AnchorableTitleTemplateSelector property.
- /// </summary>
- protected virtual void OnAnchorableTitleTemplateSelectorChanged(DependencyPropertyChangedEventArgs e)
- {
- if (e.NewValue != null &&
- AnchorableTitleTemplate != null)
- AnchorableTitleTemplate = null;
- }
- #endregion
- #region AnchorableHeaderTemplate
- /// <summary>
- /// AnchorableHeaderTemplate Dependency Property
- /// </summary>
- public static readonly DependencyProperty AnchorableHeaderTemplateProperty =
- DependencyProperty.Register("AnchorableHeaderTemplate", typeof(DataTemplate), typeof(DockingManager),
- new FrameworkPropertyMetadata((DataTemplate)null,
- new PropertyChangedCallback(OnAnchorableHeaderTemplateChanged),
- new CoerceValueCallback(CoerceAnchorableHeaderTemplateValue)));
- /// <summary>
- /// Gets or sets the AnchorableHeaderTemplate property. This dependency property
- /// indicates the data template to use for anchorable templates.
- /// </summary>
- public DataTemplate AnchorableHeaderTemplate
- {
- get { return (DataTemplate)GetValue(AnchorableHeaderTemplateProperty); }
- set { SetValue(AnchorableHeaderTemplateProperty, value); }
- }
- /// <summary>
- /// Handles changes to the AnchorableHeaderTemplate property.
- /// </summary>
- private static void OnAnchorableHeaderTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((DockingManager)d).OnAnchorableHeaderTemplateChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the AnchorableHeaderTemplate property.
- /// </summary>
- protected virtual void OnAnchorableHeaderTemplateChanged(DependencyPropertyChangedEventArgs e)
- {
- }
- /// <summary>
- /// Coerces the AnchorableHeaderTemplate value.
- /// </summary>
- private static object CoerceAnchorableHeaderTemplateValue(DependencyObject d, object value)
- {
- if (value != null &&
- d.GetValue(AnchorableHeaderTemplateSelectorProperty) != null)
- return null;
- return value;
- }
- #endregion
- #region AnchorableHeaderTemplateSelector
- /// <summary>
- /// AnchorableHeaderTemplateSelector Dependency Property
- /// </summary>
- public static readonly DependencyProperty AnchorableHeaderTemplateSelectorProperty =
- DependencyProperty.Register("AnchorableHeaderTemplateSelector", typeof(DataTemplateSelector), typeof(DockingManager),
- new FrameworkPropertyMetadata((DataTemplateSelector)null,
- new PropertyChangedCallback(OnAnchorableHeaderTemplateSelectorChanged)));
- /// <summary>
- /// Gets or sets the AnchorableHeaderTemplateSelector property. This dependency property
- /// indicates the selector to use when selecting the data template for anchorable headers.
- /// </summary>
- public DataTemplateSelector AnchorableHeaderTemplateSelector
- {
- get { return (DataTemplateSelector)GetValue(AnchorableHeaderTemplateSelectorProperty); }
- set { SetValue(AnchorableHeaderTemplateSelectorProperty, value); }
- }
- /// <summary>
- /// Handles changes to the AnchorableHeaderTemplateSelector property.
- /// </summary>
- private static void OnAnchorableHeaderTemplateSelectorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((DockingManager)d).OnAnchorableHeaderTemplateSelectorChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the AnchorableHeaderTemplateSelector property.
- /// </summary>
- protected virtual void OnAnchorableHeaderTemplateSelectorChanged(DependencyPropertyChangedEventArgs e)
- {
- if (e.NewValue != null)
- AnchorableHeaderTemplate = null;
- }
- #endregion
- protected override void OnGotKeyboardFocus(System.Windows.Input.KeyboardFocusChangedEventArgs e)
- {
- //if (e.NewFocus is Grid)
- // Trace.WriteLine(string.Format("DockingManager.OnGotKeyboardFocus({0})", e.NewFocus));
- base.OnGotKeyboardFocus(e);
- }
- protected override void OnPreviewGotKeyboardFocus(System.Windows.Input.KeyboardFocusChangedEventArgs e)
- {
- Trace.WriteLine(string.Format("DockingManager.OnPreviewGotKeyboardFocus({0})", e.NewFocus));
- base.OnPreviewGotKeyboardFocus(e);
- }
- protected override void OnPreviewLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
- {
- Trace.WriteLine(string.Format("DockingManager.OnPreviewLostKeyboardFocus({0})", e.OldFocus));
- base.OnPreviewLostKeyboardFocus(e);
- }
- protected override void OnMouseLeftButtonDown(System.Windows.Input.MouseButtonEventArgs e)
- {
- Trace.WriteLine(string.Format("DockingManager.OnMouseLeftButtonDown([{0}])", e.GetPosition(this)));
- base.OnMouseLeftButtonDown(e);
- }
- protected override void OnMouseMove(System.Windows.Input.MouseEventArgs e)
- {
- //Trace.WriteLine(string.Format("DockingManager.OnMouseMove([{0}])", e.GetPosition(this)));
- base.OnMouseMove(e);
- }
- #region LayoutRootPanel
- /// <summary>
- /// LayoutRootPanel Dependency Property
- /// </summary>
- public static readonly DependencyProperty LayoutRootPanelProperty =
- DependencyProperty.Register("LayoutRootPanel", typeof(LayoutPanelControl), typeof(DockingManager),
- new FrameworkPropertyMetadata((LayoutPanelControl)null,
- new PropertyChangedCallback(OnLayoutRootPanelChanged)));
- /// <summary>
- /// Gets or sets the LayoutRootPanel property. This dependency property
- /// indicates the layout panel control which is attached to the Layout.Root property.
- /// </summary>
- public LayoutPanelControl LayoutRootPanel
- {
- get { return (LayoutPanelControl)GetValue(LayoutRootPanelProperty); }
- set { SetValue(LayoutRootPanelProperty, value); }
- }
- /// <summary>
- /// Handles changes to the LayoutRootPanel property.
- /// </summary>
- private static void OnLayoutRootPanelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((DockingManager)d).OnLayoutRootPanelChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the LayoutRootPanel property.
- /// </summary>
- protected virtual void OnLayoutRootPanelChanged(DependencyPropertyChangedEventArgs e)
- {
- if (e.OldValue != null)
- InternalRemoveLogicalChild(e.OldValue);
- if (e.NewValue != null)
- InternalAddLogicalChild(e.NewValue);
- }
- #endregion
- #region RightSidePanel
- /// <summary>
- /// RightSidePanel Dependency Property
- /// </summary>
- public static readonly DependencyProperty RightSidePanelProperty =
- DependencyProperty.Register("RightSidePanel", typeof(LayoutAnchorSideControl), typeof(DockingManager),
- new FrameworkPropertyMetadata((LayoutAnchorSideControl)null,
- new PropertyChangedCallback(OnRightSidePanelChanged)));
- /// <summary>
- /// Gets or sets the RightSidePanel property. This dependency property
- /// indicates right side anchor panel.
- /// </summary>
- public LayoutAnchorSideControl RightSidePanel
- {
- get { return (LayoutAnchorSideControl)GetValue(RightSidePanelProperty); }
- set { SetValue(RightSidePanelProperty, value); }
- }
- /// <summary>
- /// Handles changes to the RightSidePanel property.
- /// </summary>
- private static void OnRightSidePanelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((DockingManager)d).OnRightSidePanelChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the RightSidePanel property.
- /// </summary>
- protected virtual void OnRightSidePanelChanged(DependencyPropertyChangedEventArgs e)
- {
- if (e.OldValue != null)
- InternalRemoveLogicalChild(e.OldValue);
- if (e.NewValue != null)
- InternalAddLogicalChild(e.NewValue);
- }
- #endregion
- #region LeftSidePanel
- /// <summary>
- /// LeftSidePanel Dependency Property
- /// </summary>
- public static readonly DependencyProperty LeftSidePanelProperty =
- DependencyProperty.Register("LeftSidePanel", typeof(LayoutAnchorSideControl), typeof(DockingManager),
- new FrameworkPropertyMetadata((LayoutAnchorSideControl)null,
- new PropertyChangedCallback(OnLeftSidePanelChanged)));
- /// <summary>
- /// Gets or sets the LeftSidePanel property. This dependency property
- /// indicates the left side panel control.
- /// </summary>
- public LayoutAnchorSideControl LeftSidePanel
- {
- get { return (LayoutAnchorSideControl)GetValue(LeftSidePanelProperty); }
- set { SetValue(LeftSidePanelProperty, value); }
- }
- /// <summary>
- /// Handles changes to the LeftSidePanel property.
- /// </summary>
- private static void OnLeftSidePanelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((DockingManager)d).OnLeftSidePanelChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the LeftSidePanel property.
- /// </summary>
- protected virtual void OnLeftSidePanelChanged(DependencyPropertyChangedEventArgs e)
- {
- if (e.OldValue != null)
- InternalRemoveLogicalChild(e.OldValue);
- if (e.NewValue != null)
- InternalAddLogicalChild(e.NewValue);
- }
- #endregion
- #region TopSidePanel
- /// <summary>
- /// TopSidePanel Dependency Property
- /// </summary>
- public static readonly DependencyProperty TopSidePanelProperty =
- DependencyProperty.Register("TopSidePanel", typeof(LayoutAnchorSideControl), typeof(DockingManager),
- new FrameworkPropertyMetadata((LayoutAnchorSideControl)null,
- new PropertyChangedCallback(OnTopSidePanelChanged)));
- /// <summary>
- /// Gets or sets the TopSidePanel property. This dependency property
- /// indicates top side control panel.
- /// </summary>
- public LayoutAnchorSideControl TopSidePanel
- {
- get { return (LayoutAnchorSideControl)GetValue(TopSidePanelProperty); }
- set { SetValue(TopSidePanelProperty, value); }
- }
- /// <summary>
- /// Handles changes to the TopSidePanel property.
- /// </summary>
- private static void OnTopSidePanelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((DockingManager)d).OnTopSidePanelChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the TopSidePanel property.
- /// </summary>
- protected virtual void OnTopSidePanelChanged(DependencyPropertyChangedEventArgs e)
- {
- if (e.OldValue != null)
- InternalRemoveLogicalChild(e.OldValue);
- if (e.NewValue != null)
- InternalAddLogicalChild(e.NewValue);
- }
- #endregion
- #region BottomSidePanel
- /// <summary>
- /// BottomSidePanel Dependency Property
- /// </summary>
- public static readonly DependencyProperty BottomSidePanelProperty =
- DependencyProperty.Register("BottomSidePanel", typeof(LayoutAnchorSideControl), typeof(DockingManager),
- new FrameworkPropertyMetadata((LayoutAnchorSideControl)null,
- new PropertyChangedCallback(OnBottomSidePanelChanged)));
- /// <summary>
- /// Gets or sets the BottomSidePanel property. This dependency property
- /// indicates bottom side panel control.
- /// </summary>
- public LayoutAnchorSideControl BottomSidePanel
- {
- get { return (LayoutAnchorSideControl)GetValue(BottomSidePanelProperty); }
- set { SetValue(BottomSidePanelProperty, value); }
- }
- /// <summary>
- /// Handles changes to the BottomSidePanel property.
- /// </summary>
- private static void OnBottomSidePanelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((DockingManager)d).OnBottomSidePanelChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the BottomSidePanel property.
- /// </summary>
- protected virtual void OnBottomSidePanelChanged(DependencyPropertyChangedEventArgs e)
- {
- if (e.OldValue != null)
- InternalRemoveLogicalChild(e.OldValue);
- if (e.NewValue != null)
- InternalAddLogicalChild(e.NewValue);
- }
- #endregion
- #region LogicalChildren
- List<WeakReference> _logicalChildren = new List<WeakReference>();
- protected override System.Collections.IEnumerator LogicalChildren
- {
- get
- {
- return _logicalChildren.Select(ch => ch.GetValueOrDefault<object>()).GetEnumerator();
- }
- }
- internal void InternalAddLogicalChild(object element)
- {
- //System.Diagnostics.Trace.WriteLine("[{0}]InternalAddLogicalChild({1})", this, element);
- #if DEBUG
- if (_logicalChildren.Select(ch => ch.GetValueOrDefault<object>()).Contains(element))
- new InvalidOperationException();
- #endif
- if (_logicalChildren.Select(ch => ch.GetValueOrDefault<object>()).Contains(element))
- return;
- _logicalChildren.Add(new WeakReference(element));
- AddLogicalChild(element);
- }
- internal void InternalRemoveLogicalChild(object element)
- {
- //System.Diagnostics.Trace.WriteLine("[{0}]InternalRemoveLogicalChild({1})", this, element);
- var wrToRemove = _logicalChildren.FirstOrDefault(ch => ch.GetValueOrDefault<object>() == element);
- if (wrToRemove != null)
- _logicalChildren.Remove(wrToRemove);
- RemoveLogicalChild(element);
- }
- void ClearLogicalChildrenList()
- {
- foreach (var child in _logicalChildren.Select(ch => ch.GetValueOrDefault<object>()).ToArray())
- RemoveLogicalChild(child);
- _logicalChildren.Clear();
- }
- #endregion
- #region AutoHide window
- internal void ShowAutoHideWindow(LayoutAnchorControl anchor)
- {
- _autoHideWindowManager.ShowAutoHideWindow(anchor);
- //if (_autohideArea == null)
- // return;
- //if (AutoHideWindow != null && AutoHideWindow.Model == anchor.Model)
- // return;
- //Trace.WriteLine("ShowAutoHideWindow()");
- //_currentAutohiddenAnchor = new WeakReference(anchor);
- //HideAutoHideWindow(anchor);
- //SetAutoHideWindow(new LayoutAutoHideWindowControl(anchor));
- //AutoHideWindow.Show();
- }
- internal void HideAutoHideWindow(LayoutAnchorControl anchor)
- {
- _autoHideWindowManager.HideAutoWindow(anchor);
- }
- void SetupAutoHideWindow()
- {
- _autohideArea = GetTemplateChild("PART_AutoHideArea") as FrameworkElement;
- if (_autoHideWindowManager != null)
- _autoHideWindowManager.HideAutoWindow();
- else
- _autoHideWindowManager = new AutoHideWindowManager(this);
- if (AutoHideWindow != null)
- AutoHideWindow.Dispose();
- SetAutoHideWindow(new LayoutAutoHideWindowControl());
- }
- AutoHideWindowManager _autoHideWindowManager;
- FrameworkElement _autohideArea;
- internal FrameworkElement GetAutoHideAreaElement()
- {
- return _autohideArea;
- }
- #region AutoHideWindow
- /// <summary>
- /// AutoHideWindow Read-Only Dependency Property
- /// </summary>
- private static readonly DependencyPropertyKey AutoHideWindowPropertyKey
- = DependencyProperty.RegisterReadOnly("AutoHideWindow", typeof(LayoutAutoHideWindowControl), typeof(DockingManager),
- new FrameworkPropertyMetadata((LayoutAutoHideWindowControl)null,
- new PropertyChangedCallback(OnAutoHideWindowChanged)));
- public static readonly DependencyProperty AutoHideWindowProperty
- = AutoHideWindowPropertyKey.DependencyProperty;
- /// <summary>
- /// Gets the AutoHideWindow property. This dependency property
- /// indicates the currently shown autohide window.
- /// </summary>
- public LayoutAutoHideWindowControl AutoHideWindow
- {
- get { return (LayoutAutoHideWindowControl)GetValue(AutoHideWindowProperty); }
- }
- /// <summary>
- /// Provides a secure method for setting the AutoHideWindow property.
- /// This dependency property indicates the currently shown autohide window.
- /// </summary>
- /// <param name="value">The new value for the property.</param>
- protected void SetAutoHideWindow(LayoutAutoHideWindowControl value)
- {
- SetValue(AutoHideWindowPropertyKey, value);
- }
- /// <summary>
- /// Handles changes to the AutoHideWindow property.
- /// </summary>
- private static void OnAutoHideWindowChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((DockingManager)d).OnAutoHideWindowChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the AutoHideWindow property.
- /// </summary>
- protected virtual void OnAutoHideWindowChanged(DependencyPropertyChangedEventArgs e)
- {
- if (e.OldValue != null)
- InternalRemoveLogicalChild(e.OldValue);
- if (e.NewValue != null)
- InternalAddLogicalChild(e.NewValue);
- }
- #endregion
- #endregion
- // #region AutoHide window
- //WeakReference _currentAutohiddenAnchor = null;
- //internal void ShowAutoHideWindow(LayoutAnchorControl anchor)
- //{
- // if (_autohideArea == null)
- // return;
- // if (AutoHideWindow != null && AutoHideWindow.Model == anchor.Model)
- // return;
- // Trace.WriteLine("ShowAutoHideWindow()");
- // _currentAutohiddenAnchor = new WeakReference(anchor);
- // HideAutoHideWindow(anchor);
- // SetAutoHideWindow(new LayoutAutoHideWindowControl(anchor));
- //}
- //internal void HideAutoHideWindow(LayoutAnchorControl anchor)
- //{
- // if (AutoHideWindow != null)
- // {
- // if (anchor == _currentAutohiddenAnchor.GetValueOrDefault<LayoutAnchorControl>())
- // {
- // Trace.WriteLine("AutoHideWindow()");
- // AutoHideWindow.Dispose();
- // SetAutoHideWindow(null);
- // }
- // }
- //}
- //FrameworkElement _autohideArea;
- //internal FrameworkElement GetAutoHideAreaElement()
- //{
- // return _autohideArea;
- //}
- //void SetupAutoHideArea()
- //{
- // _autohideArea = GetTemplateChild("PART_AutoHideArea") as FrameworkElement;
- //}
- // #region AutoHideWindow
- ///// <summary>
- ///// AutoHideWindow Read-Only Dependency Property
- ///// </summary>
- //private static readonly DependencyPropertyKey AutoHideWindowPropertyKey
- // = DependencyProperty.RegisterReadOnly("AutoHideWindow", typeof(LayoutAutoHideWindowControl), typeof(DockingManager),
- // new FrameworkPropertyMetadata((LayoutAutoHideWindowControl)null,
- // new PropertyChangedCallback(OnAutoHideWindowChanged)));
- //public static readonly DependencyProperty AutoHideWindowProperty
- // = AutoHideWindowPropertyKey.DependencyProperty;
- ///// <summary>
- ///// Gets the AutoHideWindow property. This dependency property
- ///// indicates the currently shown autohide window.
- ///// </summary>
- //public LayoutAutoHideWindowControl AutoHideWindow
- //{
- // get { return (LayoutAutoHideWindowControl)GetValue(AutoHideWindowProperty); }
- //}
- ///// <summary>
- ///// Provides a secure method for setting the AutoHideWindow property.
- ///// This dependency property indicates the currently shown autohide window.
- ///// </summary>
- ///// <param name="value">The new value for the property.</param>
- //protected void SetAutoHideWindow(LayoutAutoHideWindowControl value)
- //{
- // SetValue(AutoHideWindowPropertyKey, value);
- //}
- ///// <summary>
- ///// Handles changes to the AutoHideWindow property.
- ///// </summary>
- //private static void OnAutoHideWindowChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- //{
- // ((DockingManager)d).OnAutoHideWindowChanged(e);
- //}
- ///// <summary>
- ///// Provides derived classes an opportunity to handle changes to the AutoHideWindow property.
- ///// </summary>
- //protected virtual void OnAutoHideWindowChanged(DependencyPropertyChangedEventArgs e)
- //{
- // if (e.OldValue != null)
- // ((ILogicalChildrenContainer)this).InternalRemoveLogicalChild(e.OldValue);
- // if (e.NewValue != null)
- // ((ILogicalChildrenContainer)this).InternalAddLogicalChild(e.NewValue);
- //}
- // #endregion
- // #endregion
- #region Floating Windows
- List<LayoutFloatingWindowControl> _fwList = new List<LayoutFloatingWindowControl>();
- internal void StartDraggingFloatingWindowForContent(LayoutContent contentModel, bool startDrag = true)
- {
- if (!contentModel.CanFloat)
- return;
- var contentModelAsAnchorable = contentModel as LayoutAnchorable;
- if (contentModelAsAnchorable != null &&
- contentModelAsAnchorable.IsAutoHidden)
- contentModelAsAnchorable.ToggleAutoHide();
- var parentPane = contentModel.Parent as ILayoutPane;
- var parentPaneAsPositionableElement = contentModel.Parent as ILayoutPositionableElement;
- var parentPaneAsWithActualSize = contentModel.Parent as ILayoutPositionableElementWithActualSize;
- var contentModelParentChildrenIndex = parentPane.Children.ToList().IndexOf(contentModel);
- if (contentModel.FindParent<LayoutFloatingWindow>() == null)
- {
- ((ILayoutPreviousContainer)contentModel).PreviousContainer = parentPane;
- contentModel.PreviousContainerIndex = contentModelParentChildrenIndex;
- }
- parentPane.RemoveChildAt(contentModelParentChildrenIndex);
- double fwWidth = contentModel.FloatingWidth;
- double fwHeight = contentModel.FloatingHeight;
- if (fwWidth == 0.0)
- fwWidth = parentPaneAsPositionableElement.FloatingWidth;
- if (fwHeight == 0.0)
- fwHeight = parentPaneAsPositionableElement.FloatingHeight;
- if (fwWidth == 0.0)
- fwWidth = parentPaneAsWithActualSize.ActualWidth;
- if (fwHeight == 0.0)
- fwHeight = parentPaneAsWithActualSize.ActualHeight;
- LayoutFloatingWindow fw;
- LayoutFloatingWindowControl fwc;
- if (contentModel is LayoutAnchorable)
- {
- var anchorableContent = contentModel as LayoutAnchorable;
- fw = new LayoutAnchorableFloatingWindow()
- {
- RootPanel = new LayoutAnchorablePaneGroup(
- new LayoutAnchorablePane(anchorableContent)
- {
- DockWidth = parentPaneAsPositionableElement.DockWidth,
- DockHeight = parentPaneAsPositionableElement.DockHeight,
- DockMinHeight = parentPaneAsPositionableElement.DockMinHeight,
- DockMinWidth = parentPaneAsPositionableElement.DockMinWidth,
- FloatingLeft = parentPaneAsPositionableElement.FloatingLeft,
- FloatingTop = parentPaneAsPositionableElement.FloatingTop,
- FloatingWidth = parentPaneAsPositionableElement.FloatingWidth,
- FloatingHeight = parentPaneAsPositionableElement.FloatingHeight,
- })
- };
- Layout.FloatingWindows.Add(fw);
- fwc = new LayoutAnchorableFloatingWindowControl(
- fw as LayoutAnchorableFloatingWindow)
- {
- Width = fwWidth,
- Height = fwHeight,
- Left = contentModel.FloatingLeft,
- Top = contentModel.FloatingTop
- };
- }
- else
- {
- var anchorableDocument = contentModel as LayoutDocument;
- fw = new LayoutDocumentFloatingWindow()
- {
- RootDocument = anchorableDocument
- };
- Layout.FloatingWindows.Add(fw);
- fwc = new LayoutDocumentFloatingWindowControl(
- fw as LayoutDocumentFloatingWindow)
- {
- Width = fwWidth,
- Height = fwHeight,
- Left = contentModel.FloatingLeft,
- Top = contentModel.FloatingTop
- };
- }
- //fwc.Owner = Window.GetWindow(this);
- //fwc.SetParentToMainWindowOf(this);
- _fwList.Add(fwc);
- Layout.CollectGarbage();
- UpdateLayout();
- Dispatcher.BeginInvoke(new Action(() =>
- {
- if (startDrag)
- fwc.AttachDrag();
- fwc.Show();
- }), DispatcherPriority.Send);
- }
- internal void StartDraggingFloatingWindowForPane(LayoutAnchorablePane paneModel)
- {
- if (paneModel.Children.Any(c => !c.CanFloat))
- return;
- var paneAsPositionableElement = paneModel as ILayoutPositionableElement;
- var paneAsWithActualSize = paneModel as ILayoutPositionableElementWithActualSize;
- double fwWidth = paneAsPositionableElement.FloatingWidth;
- double fwHeight = paneAsPositionableElement.FloatingHeight;
- double fwLeft = paneAsPositionableElement.FloatingLeft;
- double fwTop = paneAsPositionableElement.FloatingTop;
- if (fwWidth == 0.0)
- fwWidth = paneAsWithActualSize.ActualWidth;
- if (fwHeight == 0.0)
- fwHeight = paneAsWithActualSize.ActualHeight;
- var destPane = new LayoutAnchorablePane()
- {
- DockWidth = paneAsPositionableElement.DockWidth,
- DockHeight = paneAsPositionableElement.DockHeight,
- DockMinHeight = paneAsPositionableElement.DockMinHeight,
- DockMinWidth = paneAsPositionableElement.DockMinWidth,
- FloatingLeft = paneAsPositionableElement.FloatingLeft,
- FloatingTop = paneAsPositionableElement.FloatingTop,
- FloatingWidth = paneAsPositionableElement.FloatingWidth,
- FloatingHeight = paneAsPositionableElement.FloatingHeight,
- };
- bool savePreviousContainer = paneModel.FindParent<LayoutFloatingWindow>() == null;
- int currentSelectedContentIndex = paneModel.SelectedContentIndex;
- while (paneModel.Children.Count > 0)
- {
- var contentModel = paneModel.Children[paneModel.Children.Count - 1] as LayoutAnchorable;
- if (savePreviousContainer)
- {
- var contentModelAsPreviousContainer = contentModel as ILayoutPreviousContainer;
- contentModelAsPreviousContainer.PreviousContainer = paneModel;
- contentModel.PreviousContainerIndex = paneModel.Children.Count - 1;
- }
- paneModel.RemoveChildAt(paneModel.Children.Count - 1);
- destPane.Children.Insert(0, contentModel);
- }
- if (destPane.Children.Count > 0)
- {
- destPane.SelectedContentIndex = currentSelectedContentIndex;
- }
- LayoutFloatingWindow fw;
- LayoutFloatingWindowControl fwc;
- fw = new LayoutAnchorableFloatingWindow()
- {
- RootPanel = new LayoutAnchorablePaneGroup(
- destPane)
- {
- DockHeight = destPane.DockHeight,
- DockWidth = destPane.DockWidth,
- DockMinHeight = destPane.DockMinHeight,
- DockMinWidth = destPane.DockMinWidth,
- }
- };
- Layout.FloatingWindows.Add(fw);
- fwc = new LayoutAnchorableFloatingWindowControl(
- fw as LayoutAnchorableFloatingWindow)
- {
- Width = fwWidth,
- Height = fwHeight
- };
- //fwc.Owner = Window.GetWindow(this);
- //fwc.SetParentToMainWindowOf(this);
- _fwList.Add(fwc);
- Layout.CollectGarbage();
- InvalidateArrange();
- fwc.AttachDrag();
- fwc.Show();
- }
- internal IEnumerable<LayoutFloatingWindowControl> GetFloatingWindowsByZOrder()
- {
- var parentWindow = Window.GetWindow(this);
- if (parentWindow == null)
- yield break;
- IntPtr windowParentHanlde = new WindowInteropHelper(parentWindow).Handle;
- IntPtr currentHandle = Win32Helper.GetWindow(windowParentHanlde, (uint)Win32Helper.GetWindow_Cmd.GW_HWNDFIRST);
- while (currentHandle != IntPtr.Zero)
- {
- LayoutFloatingWindowControl ctrl = _fwList.FirstOrDefault(fw => new WindowInteropHelper(fw).Handle == currentHandle);
- if (ctrl != null && ctrl.Model.Root.Manager == this)
- yield return ctrl;
- currentHandle = Win32Helper.GetWindow(currentHandle, (uint)Win32Helper.GetWindow_Cmd.GW_HWNDNEXT);
- }
- }
- internal void RemoveFloatingWindow(LayoutFloatingWindowControl floatingWindow)
- {
- _fwList.Remove(floatingWindow);
- }
- public IEnumerable<LayoutFloatingWindowControl> FloatingWindows
- {
- get { return _fwList; }
- }
- #endregion
- #region OverlayWindow
- bool IOverlayWindowHost.HitTest(Point dragPoint)
- {
- Rect detectionRect = new Rect(this.PointToScreenDPIWithoutFlowDirection(new Point()), this.TransformActualSizeToAncestor());
- return detectionRect.Contains(dragPoint);
- }
- DockingManager IOverlayWindowHost.Manager
- {
- get { return this; }
- }
- OverlayWindow _overlayWindow = null;
- void CreateOverlayWindow()
- {
- if (_overlayWindow == null)
- {
- _overlayWindow = new OverlayWindow(this);
- }
- Rect rectWindow = new Rect(this.PointToScreenDPIWithoutFlowDirection(new Point()), this.TransformActualSizeToAncestor());
- _overlayWindow.Left = rectWindow.Left;
- _overlayWindow.Top = rectWindow.Top;
- _overlayWindow.Width = rectWindow.Width;
- _overlayWindow.Height = rectWindow.Height;
- }
- void DestroyOverlayWindow()
- {
- if (_overlayWindow != null)
- {
- _overlayWindow.Close();
- _overlayWindow = null;
- }
- }
- IOverlayWindow IOverlayWindowHost.ShowOverlayWindow(LayoutFloatingWindowControl draggingWindow)
- {
- //Trace.WriteLine("ShowOverlayWindow");
- CreateOverlayWindow();
- _overlayWindow.Owner = draggingWindow;
- _overlayWindow.EnableDropTargets();
- _overlayWindow.Show();
- return _overlayWindow;
- }
- void IOverlayWindowHost.HideOverlayWindow()
- {
- //Trace.WriteLine("HideOverlayWindow");
- _areas = null;
- _overlayWindow.Owner = null;
- _overlayWindow.HideDropTargets();
- }
- List<IDropArea> _areas = null;
- IEnumerable<IDropArea> IOverlayWindowHost.GetDropAreas(LayoutFloatingWindowControl draggingWindow)
- {
- if (_areas != null)
- return _areas;
- bool isDraggingDocuments = draggingWindow.Model is LayoutDocumentFloatingWindow;
- _areas = new List<IDropArea>();
- if (!isDraggingDocuments)
- {
- _areas.Add(new DropArea<DockingManager>(
- this,
- DropAreaType.DockingManager));
- foreach (var areaHost in this.FindVisualChildren<LayoutAnchorablePaneControl>())
- {
- if (areaHost.Model.Descendents().Any())
- {
- _areas.Add(new DropArea<LayoutAnchorablePaneControl>(
- areaHost,
- DropAreaType.AnchorablePane));
- }
- }
- }
- foreach (var areaHost in this.FindVisualChildren<LayoutDocumentPaneControl>())
- {
- _areas.Add(new DropArea<LayoutDocumentPaneControl>(
- areaHost,
- DropAreaType.DocumentPane));
- }
- foreach (var areaHost in this.FindVisualChildren<LayoutDocumentPaneGroupControl>())
- {
- var documentGroupModel = areaHost.Model as LayoutDocumentPaneGroup;
- if (documentGroupModel.Children.Where(c => c.IsVisible).Count() == 0)
- {
- _areas.Add(new DropArea<LayoutDocumentPaneGroupControl>(
- areaHost,
- DropAreaType.DocumentPaneGroup));
- }
- }
- return _areas;
- }
- protected override Size ArrangeOverride(Size arrangeBounds)
- {
- _areas = null;
- return base.ArrangeOverride(arrangeBounds);
- }
- #endregion
- #region LayoutDocument & LayoutAnchorable Templates
- #region LayoutItemTemplate
- /// <summary>
- /// LayoutItemTemplate Dependency Property
- /// </summary>
- public static readonly DependencyProperty LayoutItemTemplateProperty =
- DependencyProperty.Register("LayoutItemTemplate", typeof(DataTemplate), typeof(DockingManager),
- new FrameworkPropertyMetadata((DataTemplate)null,
- new PropertyChangedCallback(OnLayoutItemTemplateChanged)));
- /// <summary>
- /// Gets or sets the AnchorableTemplate property. This dependency property
- /// indicates the template to use to render anchorable and document contents.
- /// </summary>
- public DataTemplate LayoutItemTemplate
- {
- get { return (DataTemplate)GetValue(LayoutItemTemplateProperty); }
- set { SetValue(LayoutItemTemplateProperty, value); }
- }
- /// <summary>
- /// Handles changes to the AnchorableTemplate property.
- /// </summary>
- private static void OnLayoutItemTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((DockingManager)d).OnLayoutItemTemplateChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the AnchorableTemplate property.
- /// </summary>
- protected virtual void OnLayoutItemTemplateChanged(DependencyPropertyChangedEventArgs e)
- {
- }
- #endregion
- #region LayoutItemTemplateSelector
- /// <summary>
- /// LayoutItemTemplateSelector Dependency Property
- /// </summary>
- public static readonly DependencyProperty LayoutItemTemplateSelectorProperty =
- DependencyProperty.Register("LayoutItemTemplateSelector", typeof(DataTemplateSelector), typeof(DockingManager),
- new FrameworkPropertyMetadata((DataTemplateSelector)null,
- new PropertyChangedCallback(OnLayoutItemTemplateSelectorChanged)));
- /// <summary>
- /// Gets or sets the LayoutItemTemplateSelector property. This dependency property
- /// indicates selector object to use for anchorable templates.
- /// </summary>
- public DataTemplateSelector LayoutItemTemplateSelector
- {
- get { return (DataTemplateSelector)GetValue(LayoutItemTemplateSelectorProperty); }
- set { SetValue(LayoutItemTemplateSelectorProperty, value); }
- }
- /// <summary>
- /// Handles changes to the LayoutItemTemplateSelector property.
- /// </summary>
- private static void OnLayoutItemTemplateSelectorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((DockingManager)d).OnLayoutItemTemplateSelectorChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the LayoutItemTemplateSelector property.
- /// </summary>
- protected virtual void OnLayoutItemTemplateSelectorChanged(DependencyPropertyChangedEventArgs e)
- {
- }
- #endregion
- #endregion
- #region DocumentsSource
- /// <summary>
- /// DocumentsSource Dependency Property
- /// </summary>
- public static readonly DependencyProperty DocumentsSourceProperty =
- DependencyProperty.Register("DocumentsSource", typeof(IEnumerable), typeof(DockingManager),
- new FrameworkPropertyMetadata((IEnumerable)null,
- new PropertyChangedCallback(OnDocumentsSourceChanged)));
- /// <summary>
- /// Gets or sets the DocumentsSource property. This dependency property
- /// indicates the source collection of documents.
- /// </summary>
- public IEnumerable DocumentsSource
- {
- get { return (IEnumerable)GetValue(DocumentsSourceProperty); }
- set { SetValue(DocumentsSourceProperty, value); }
- }
- /// <summary>
- /// Handles changes to the DocumentsSource property.
- /// </summary>
- private static void OnDocumentsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((DockingManager)d).OnDocumentsSourceChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the DocumentsSource property.
- /// </summary>
- protected virtual void OnDocumentsSourceChanged(DependencyPropertyChangedEventArgs e)
- {
- DetachDocumentsSource(Layout, e.OldValue as IEnumerable);
- AttachDocumentsSource(Layout, e.NewValue as IEnumerable);
- }
- void AttachDocumentsSource(LayoutRoot layout, IEnumerable documentsSource)
- {
- if (documentsSource == null)
- return;
- if (layout == null)
- return;
- //if (layout.Descendents().OfType<LayoutDocument>().Any())
- // throw new InvalidOperationException("Unable to set the DocumentsSource property if LayoutDocument objects are already present in the model");
- var documentsImported = layout.Descendents().OfType<LayoutDocument>().Select(d => d.Content).ToArray();
- var documents = documentsSource as IEnumerable;
- var listOfDocumentsToImport = new List<object>(documents.OfType<object>());
- foreach (var document in listOfDocumentsToImport.ToArray())
- {
- if (documentsImported.Contains(document))
- listOfDocumentsToImport.Remove(document);
- }
- LayoutDocumentPane documentPane = null;
- if (layout.LastFocusedDocument != null)
- {
- documentPane = layout.LastFocusedDocument.Parent as LayoutDocumentPane;
- }
- if (documentPane == null)
- {
- documentPane = layout.Descendents().OfType<LayoutDocumentPane>().FirstOrDefault();
- }
- //if (documentPane == null)
- // throw new InvalidOperationException("Layout must contains at least one LayoutDocumentPane in order to host documents");
- _suspendLayoutItemCreation = true;
- foreach (var documentContentToImport in listOfDocumentsToImport)
- {
- //documentPane.Children.Add(new LayoutDocument() { Content = documentToImport });
- var documentToImport = new LayoutDocument()
- {
- Content = documentContentToImport
- };
- bool added = false;
- if (LayoutUpdateStrategy != null)
- {
- added = LayoutUpdateStrategy.BeforeInsertDocument(layout, documentToImport, documentPane);
- }
- if (!added)
- {
- if (documentPane == null)
- throw new InvalidOperationException("Layout must contains at least one LayoutDocumentPane in order to host documents");
- documentPane.Children.Add(documentToImport);
- added = true;
- }
- if (LayoutUpdateStrategy != null)
- LayoutUpdateStrategy.AfterInsertDocument(layout, documentToImport);
- CreateDocumentLayoutItem(documentToImport);
- }
- _suspendLayoutItemCreation = true;
- var documentsSourceAsNotifier = documentsSource as INotifyCollectionChanged;
- if (documentsSourceAsNotifier != null)
- documentsSourceAsNotifier.CollectionChanged += new NotifyCollectionChangedEventHandler(documentsSourceElementsChanged);
- }
- internal bool SuspendDocumentsSourceBinding = false;
- void documentsSourceElementsChanged(object sender, NotifyCollectionChangedEventArgs e)
- {
- if (Layout == null)
- return;
- //When deserializing documents are created automatically by the deserializer
- if (SuspendDocumentsSourceBinding)
- return;
- //handle remove
- if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove ||
- e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Replace)
- {
- if (e.OldItems != null)
- {
- var documentsToRemove = Layout.Descendents().OfType<LayoutDocument>().Where(d => e.OldItems.Contains(d.Content)).ToArray();
- foreach (var documentToRemove in documentsToRemove)
- {
- (documentToRemove.Parent as ILayoutContainer).RemoveChild(
- documentToRemove);
- }
- }
- }
- //handle add
- if (e.NewItems != null &&
- (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add ||
- e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Replace))
- {
- if (e.NewItems != null)
- {
- LayoutDocumentPane documentPane = null;
- if (Layout.LastFocusedDocument != null)
- {
- documentPane = Layout.LastFocusedDocument.Parent as LayoutDocumentPane;
- }
- if (documentPane == null)
- {
- documentPane = Layout.Descendents().OfType<LayoutDocumentPane>().FirstOrDefault();
- }
- //if (documentPane == null)
- // throw new InvalidOperationException("Layout must contains at least one LayoutDocumentPane in order to host documents");
- _suspendLayoutItemCreation = true;
- foreach (var documentContentToImport in e.NewItems)
- {
- var documentToImport = new LayoutDocument()
- {
- Content = documentContentToImport
- };
- bool added = false;
- if (LayoutUpdateStrategy != null)
- {
- added = LayoutUpdateStrategy.BeforeInsertDocument(Layout, documentToImport, documentPane);
- }
- if (!added)
- {
- if (documentPane == null)
- throw new InvalidOperationException("Layout must contains at least one LayoutDocumentPane in order to host documents");
- documentPane.Children.Add(documentToImport);
- added = true;
- }
- if (LayoutUpdateStrategy != null)
- {
- LayoutUpdateStrategy.AfterInsertDocument(Layout, documentToImport);
- }
- var root = documentToImport.Root;
- if (root != null && root.Manager == this)
- {
- CreateDocumentLayoutItem(documentToImport);
- }
- }
- _suspendLayoutItemCreation = false;
- }
- }
- if (e.Action == NotifyCollectionChangedAction.Reset)
- {
- //NOTE: I'm going to clear every document present in layout but
- //some documents may have been added directly to the layout, for now I clear them too
- var documentsToRemove = Layout.Descendents().OfType<LayoutDocument>().ToArray();
- foreach (var documentToRemove in documentsToRemove)
- {
- (documentToRemove.Parent as ILayoutContainer).RemoveChild(
- documentToRemove);
- }
- }
- if (Layout != null)
- {
- Layout.CollectGarbage();
- }
- }
- void DetachDocumentsSource(LayoutRoot layout, IEnumerable documentsSource)
- {
- if (documentsSource == null)
- return;
- if (layout == null)
- return;
- var documentsToRemove = layout.Descendents().OfType<LayoutDocument>()
- .Where(d => documentsSource.Contains(d.Content)).ToArray();
- foreach (var documentToRemove in documentsToRemove)
- {
- (documentToRemove.Parent as ILayoutContainer).RemoveChild(
- documentToRemove);
- }
- var documentsSourceAsNotifier = documentsSource as INotifyCollectionChanged;
- if (documentsSourceAsNotifier != null)
- documentsSourceAsNotifier.CollectionChanged -= new NotifyCollectionChangedEventHandler(documentsSourceElementsChanged);
- }
- #endregion
- #region DocumentCloseCommand
- internal void _ExecuteCloseCommand(LayoutDocument document)
- {
- if (DocumentClosing != null)
- {
- var evargs = new DocumentClosingEventArgs(document);
- DocumentClosing(this, evargs);
- if (evargs.Cancel)
- return;
- }
- if (!document.TestCanClose())
- return;
- document.CloseInternal();
- if (DocumentClosed != null)
- {
- var evargs = new DocumentClosedEventArgs(document);
- DocumentClosed(this, evargs);
- }
- }
- /// <summary>
- /// Event fired when a document is about to be closed
- /// </summary>
- /// <remarks>Subscribers have the opportuniy to cancel the operation.</remarks>
- public event EventHandler<DocumentClosingEventArgs> DocumentClosing;
- /// <summary>
- /// Event fired after a document is closed
- /// </summary>
- public event EventHandler<DocumentClosedEventArgs> DocumentClosed;
- #endregion
- internal void _ExecuteCloseAllButThisCommand(LayoutContent contentSelected)
- {
- foreach (var contentToClose in Layout.Descendents().OfType<LayoutContent>().Where(d => d != contentSelected && (d.Parent is LayoutDocumentPane || d.Parent is LayoutDocumentFloatingWindow)).ToArray())
- {
- if (!contentToClose.CanClose)
- continue;
- var layoutItem = GetLayoutItemFromModel(contentToClose);
- if (layoutItem.CloseCommand != null)
- {
- if (layoutItem.CloseCommand.CanExecute(null))
- layoutItem.CloseCommand.Execute(null);
- }
- else
- {
- if (contentToClose is LayoutDocument)
- _ExecuteCloseCommand(contentToClose as LayoutDocument);
- else if (contentToClose is LayoutAnchorable)
- _ExecuteCloseCommand(contentToClose as LayoutAnchorable);
- }
- }
- }
- #region DocumentContextMenu
- /// <summary>
- /// DocumentContextMenu Dependency Property
- /// </summary>
- public static readonly DependencyProperty DocumentContextMenuProperty =
- DependencyProperty.Register("DocumentContextMenu", typeof(ContextMenu), typeof(DockingManager),
- new FrameworkPropertyMetadata((ContextMenu)null));
- /// <summary>
- /// Gets or sets the DocumentContextMenu property. This dependency property
- /// indicates context menu to show for documents.
- /// </summary>
- public ContextMenu DocumentContextMenu
- {
- get { return (ContextMenu)GetValue(DocumentContextMenuProperty); }
- set { SetValue(DocumentContextMenuProperty, value); }
- }
- #endregion
- #region AnchorablesSource
- /// <summary>
- /// AnchorablesSource Dependency Property
- /// </summary>
- public static readonly DependencyProperty AnchorablesSourceProperty =
- DependencyProperty.Register("AnchorablesSource", typeof(IEnumerable), typeof(DockingManager),
- new FrameworkPropertyMetadata((IEnumerable)null,
- new PropertyChangedCallback(OnAnchorablesSourceChanged)));
- /// <summary>
- /// Gets or sets the AnchorablesSource property. This dependency property
- /// indicates source collection of anchorables.
- /// </summary>
- public IEnumerable AnchorablesSource
- {
- get { return (IEnumerable)GetValue(AnchorablesSourceProperty); }
- set { SetValue(AnchorablesSourceProperty, value); }
- }
- /// <summary>
- /// Handles changes to the AnchorablesSource property.
- /// </summary>
- private static void OnAnchorablesSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((DockingManager)d).OnAnchorablesSourceChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the AnchorablesSource property.
- /// </summary>
- protected virtual void OnAnchorablesSourceChanged(DependencyPropertyChangedEventArgs e)
- {
- DetachAnchorablesSource(Layout, e.OldValue as IEnumerable);
- AttachAnchorablesSource(Layout, e.NewValue as IEnumerable);
- }
- void AttachAnchorablesSource(LayoutRoot layout, IEnumerable anchorablesSource)
- {
- if (anchorablesSource == null)
- return;
- if (layout == null)
- return;
- //if (layout.Descendents().OfType<LayoutAnchorable>().Any())
- // throw new InvalidOperationException("Unable to set the AnchorablesSource property if LayoutAnchorable objects are already present in the model");
- var anchorablesImported = layout.Descendents().OfType<LayoutAnchorable>().Select(d => d.Content).ToArray();
- var anchorables = anchorablesSource as IEnumerable;
- var listOfAnchorablesToImport = new List<object>(anchorables.OfType<object>());
- foreach (var document in listOfAnchorablesToImport.ToArray())
- {
- if (anchorablesImported.Contains(document))
- listOfAnchorablesToImport.Remove(document);
- }
- LayoutAnchorablePane anchorablePane = null;
- if (layout.ActiveContent != null)
- {
- //look for active content parent pane
- anchorablePane = layout.ActiveContent.Parent as LayoutAnchorablePane;
- }
- if (anchorablePane == null)
- {
- //look for a pane on the right side
- anchorablePane = layout.Descendents().OfType<LayoutAnchorablePane>().Where(pane => !pane.IsHostedInFloatingWindow && pane.GetSide() == AnchorSide.Right).FirstOrDefault();
- }
- if (anchorablePane == null)
- {
- //look for an available pane
- anchorablePane = layout.Descendents().OfType<LayoutAnchorablePane>().FirstOrDefault();
- }
- _suspendLayoutItemCreation = true;
- foreach (var anchorableContentToImport in listOfAnchorablesToImport)
- {
- var anchorableToImport = new LayoutAnchorable()
- {
- Content = anchorableContentToImport
- };
- bool added = false;
- if (LayoutUpdateStrategy != null)
- {
- added = LayoutUpdateStrategy.BeforeInsertAnchorable(layout, anchorableToImport, anchorablePane);
- }
- if (!added)
- {
- if (anchorablePane == null)
- {
- var mainLayoutPanel = new LayoutPanel() { Orientation = Orientation.Horizontal };
- if (layout.RootPanel != null)
- {
- mainLayoutPanel.Children.Add(layout.RootPanel);
- }
- layout.RootPanel = mainLayoutPanel;
- anchorablePane = new LayoutAnchorablePane() { DockWidth = new GridLength(200.0, GridUnitType.Pixel) };
- mainLayoutPanel.Children.Add(anchorablePane);
- }
- anchorablePane.Children.Add(anchorableToImport);
- added = true;
- }
- if (LayoutUpdateStrategy != null)
- LayoutUpdateStrategy.AfterInsertAnchorable(layout, anchorableToImport);
- CreateAnchorableLayoutItem(anchorableToImport);
- }
- _suspendLayoutItemCreation = false;
- var anchorablesSourceAsNotifier = anchorablesSource as INotifyCollectionChanged;
- if (anchorablesSourceAsNotifier != null)
- anchorablesSourceAsNotifier.CollectionChanged += new NotifyCollectionChangedEventHandler(anchorablesSourceElementsChanged);
- }
- internal bool SuspendAnchorablesSourceBinding = false;
- void anchorablesSourceElementsChanged(object sender, NotifyCollectionChangedEventArgs e)
- {
- if (Layout == null)
- return;
- //When deserializing documents are created automatically by the deserializer
- if (SuspendAnchorablesSourceBinding)
- return;
- //handle remove
- if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove ||
- e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Replace)
- {
- if (e.OldItems != null)
- {
- var anchorablesToRemove = Layout.Descendents().OfType<LayoutAnchorable>().Where(d => e.OldItems.Contains(d.Content)).ToArray();
- foreach (var anchorableToRemove in anchorablesToRemove)
- {
- (anchorableToRemove.Parent as ILayoutContainer).RemoveChild(
- anchorableToRemove);
- }
- }
- }
- //handle add
- if (e.NewItems != null &&
- (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add ||
- e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Replace))
- {
- if (e.NewItems != null)
- {
- LayoutAnchorablePane anchorablePane = null;
- if (Layout.ActiveContent != null)
- {
- //look for active content parent pane
- anchorablePane = Layout.ActiveContent.Parent as LayoutAnchorablePane;
- }
- if (anchorablePane == null)
- {
- //look for a pane on the right side
- anchorablePane = Layout.Descendents().OfType<LayoutAnchorablePane>().Where(pane => !pane.IsHostedInFloatingWindow && pane.GetSide() == AnchorSide.Right).FirstOrDefault();
- }
- if (anchorablePane == null)
- {
- //look for an available pane
- anchorablePane = Layout.Descendents().OfType<LayoutAnchorablePane>().FirstOrDefault();
- }
- _suspendLayoutItemCreation = true;
- foreach (var anchorableContentToImport in e.NewItems)
- {
- var anchorableToImport = new LayoutAnchorable()
- {
- Content = anchorableContentToImport
- };
- bool added = false;
- if (LayoutUpdateStrategy != null)
- {
- added = LayoutUpdateStrategy.BeforeInsertAnchorable(Layout, anchorableToImport, anchorablePane);
- }
- if (!added)
- {
- if (anchorablePane == null)
- {
- var mainLayoutPanel = new LayoutPanel() { Orientation = Orientation.Horizontal };
- if (Layout.RootPanel != null)
- {
- mainLayoutPanel.Children.Add(Layout.RootPanel);
- }
- Layout.RootPanel = mainLayoutPanel;
- anchorablePane = new LayoutAnchorablePane() { DockWidth = new GridLength(200.0, GridUnitType.Pixel) };
- mainLayoutPanel.Children.Add(anchorablePane);
- }
- anchorablePane.Children.Add(anchorableToImport);
- added = true;
- }
- if (LayoutUpdateStrategy != null)
- {
- LayoutUpdateStrategy.AfterInsertAnchorable(Layout, anchorableToImport);
- }
- var root = anchorableToImport.Root;
- if (root != null && root.Manager == this)
- {
- CreateAnchorableLayoutItem(anchorableToImport);
- }
- }
- _suspendLayoutItemCreation = false;
- }
- }
- if (e.Action == NotifyCollectionChangedAction.Reset)
- {
- //NOTE: I'm going to clear every anchorable present in layout but
- //some anchorable may have been added directly to the layout, for now I clear them too
- var anchorablesToRemove = Layout.Descendents().OfType<LayoutAnchorable>().ToArray();
- foreach (var anchorableToRemove in anchorablesToRemove)
- {
- (anchorableToRemove.Parent as ILayoutContainer).RemoveChild(
- anchorableToRemove);
- }
- }
- if (Layout != null)
- Layout.CollectGarbage();
- }
- void DetachAnchorablesSource(LayoutRoot layout, IEnumerable anchorablesSource)
- {
- if (anchorablesSource == null)
- return;
- if (layout == null)
- return;
- var anchorablesToRemove = layout.Descendents().OfType<LayoutAnchorable>()
- .Where(d => anchorablesSource.Contains(d.Content)).ToArray();
- foreach (var anchorableToRemove in anchorablesToRemove)
- {
- (anchorableToRemove.Parent as ILayoutContainer).RemoveChild(
- anchorableToRemove);
- }
- var anchorablesSourceAsNotifier = anchorablesSource as INotifyCollectionChanged;
- if (anchorablesSourceAsNotifier != null)
- anchorablesSourceAsNotifier.CollectionChanged -= new NotifyCollectionChangedEventHandler(anchorablesSourceElementsChanged);
- }
- #endregion
- internal void _ExecuteCloseCommand(LayoutAnchorable anchorable)
- {
- var model = anchorable as LayoutAnchorable;
- if (model != null && model.TestCanClose())
- {
- if (model.IsAutoHidden)
- model.ToggleAutoHide();
- //Daniel-调Close()会死循环
- //model.Close();
- model.CloseInternal();
- return;
- }
- }
- internal void _ExecuteHideCommand(LayoutAnchorable anchorable)
- {
- var model = anchorable as LayoutAnchorable;
- if (model != null)
- {
- //by default hide the anchorable
- model.Hide();
- }
- }
- internal void _ExecuteAutoHideCommand(LayoutAnchorable _anchorable)
- {
- _anchorable.ToggleAutoHide();
- }
- internal void _ExecuteFloatCommand(LayoutContent contentToFloat)
- {
- contentToFloat.Float();
- }
- internal void _ExecuteDockCommand(LayoutAnchorable anchorable)
- {
- anchorable.Dock();
- }
- internal void _ExecuteDockAsDocumentCommand(LayoutContent content)
- {
- content.DockAsDocument();
- }
- #region ActiveContent
- /// <summary>
- /// ActiveContent Dependency Property
- /// </summary>
- public static readonly DependencyProperty ActiveContentProperty =
- DependencyProperty.Register("ActiveContent", typeof(object), typeof(DockingManager),
- new FrameworkPropertyMetadata((object)null,
- new PropertyChangedCallback(OnActiveContentChanged)));
- /// <summary>
- /// Gets or sets the ActiveContent property. This dependency property
- /// indicates the content currently active.
- /// </summary>
- public object ActiveContent
- {
- get { return (object)GetValue(ActiveContentProperty); }
- set { SetValue(ActiveContentProperty, value); }
- }
- /// <summary>
- /// Handles changes to the ActiveContent property.
- /// </summary>
- private static void OnActiveContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((DockingManager)d).InternalSetActiveContent(e.NewValue);
- ((DockingManager)d).OnActiveContentChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the ActiveContent property.
- /// </summary>
- protected virtual void OnActiveContentChanged(DependencyPropertyChangedEventArgs e)
- {
- if (ActiveContentChanged != null)
- ActiveContentChanged(this, EventArgs.Empty);
- }
- bool _insideInternalSetActiveContent = false;
- void InternalSetActiveContent(object contentObject)
- {
- var layoutContent = Layout.Descendents().OfType<LayoutContent>().FirstOrDefault(lc => lc == contentObject || lc.Content == contentObject);
- _insideInternalSetActiveContent = true;
- Layout.ActiveContent = layoutContent;
- _insideInternalSetActiveContent = false;
- }
- public event EventHandler ActiveContentChanged;
- #endregion
- #region AnchorableContextMenu
- /// <summary>
- /// AnchorableContextMenu Dependency Property
- /// </summary>
- public static readonly DependencyProperty AnchorableContextMenuProperty =
- DependencyProperty.Register("AnchorableContextMenu", typeof(ContextMenu), typeof(DockingManager),
- new FrameworkPropertyMetadata((ContextMenu)null));
- /// <summary>
- /// Gets or sets the AnchorableContextMenu property. This dependency property
- /// indicates the context menu to show up for anchorables.
- /// </summary>
- public ContextMenu AnchorableContextMenu
- {
- get { return (ContextMenu)GetValue(AnchorableContextMenuProperty); }
- set { SetValue(AnchorableContextMenuProperty, value); }
- }
- #endregion
- #region Theme
- /// <summary>
- /// Theme Dependency Property
- /// </summary>
- public static readonly DependencyProperty ThemeProperty =
- DependencyProperty.Register("Theme", typeof(Theme), typeof(DockingManager),
- new FrameworkPropertyMetadata(null,
- new PropertyChangedCallback(OnThemeChanged)));
- /// <summary>
- /// Gets or sets the Theme property. This dependency property
- /// indicates the theme to use for AvalonDock controls.
- /// </summary>
- public Theme Theme
- {
- get { return (Theme)GetValue(ThemeProperty); }
- set { SetValue(ThemeProperty, value); }
- }
- /// <summary>
- /// Handles changes to the Theme property.
- /// </summary>
- private static void OnThemeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((DockingManager)d).OnThemeChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the Theme property.
- /// </summary>
- protected virtual void OnThemeChanged(DependencyPropertyChangedEventArgs e)
- {
- var oldTheme = e.OldValue as Theme;
- var newTheme = e.NewValue as Theme;
- var resources = this.Resources;
- if (oldTheme != null)
- {
- if (oldTheme is DictionaryTheme)
- {
- if (currentThemeResourceDictionary != null)
- {
- resources.MergedDictionaries.Remove(currentThemeResourceDictionary);
- currentThemeResourceDictionary = null;
- }
- }
- else
- {
- var resourceDictionaryToRemove =
- resources.MergedDictionaries.FirstOrDefault(r => r.Source == oldTheme.GetResourceUri());
- if (resourceDictionaryToRemove != null)
- resources.MergedDictionaries.Remove(
- resourceDictionaryToRemove);
- }
- }
- if (newTheme != null)
- {
- if (newTheme is DictionaryTheme)
- {
- currentThemeResourceDictionary = ((DictionaryTheme)newTheme).ThemeResourceDictionary;
- resources.MergedDictionaries.Add(currentThemeResourceDictionary);
- }
- else
- {
- resources.MergedDictionaries.Add(new ResourceDictionary() { Source = newTheme.GetResourceUri() });
- }
- }
- foreach (var fwc in _fwList)
- fwc.UpdateThemeResources(oldTheme);
- if (_navigatorWindow != null)
- _navigatorWindow.UpdateThemeResources();
- if (_overlayWindow != null)
- _overlayWindow.UpdateThemeResources();
- }
- #endregion
- #region GridSplitterWidth
- /// <summary>
- /// GridSplitterWidth Dependency Property
- /// </summary>
- public static readonly DependencyProperty GridSplitterWidthProperty =
- DependencyProperty.Register("GridSplitterWidth", typeof(double), typeof(DockingManager),
- new FrameworkPropertyMetadata((double)6.0));
- /// <summary>
- /// Gets or sets the GridSplitterWidth property. This dependency property
- /// indicates width of grid splitters.
- /// </summary>
- public double GridSplitterWidth
- {
- get { return (double)GetValue(GridSplitterWidthProperty); }
- set { SetValue(GridSplitterWidthProperty, value); }
- }
- #endregion
- #region GridSplitterHeight
- /// <summary>
- /// GridSplitterHeight Dependency Property
- /// </summary>
- public static readonly DependencyProperty GridSplitterHeightProperty =
- DependencyProperty.Register("GridSplitterHeight", typeof(double), typeof(DockingManager),
- new FrameworkPropertyMetadata((double)6.0));
- /// <summary>
- /// Gets or sets the GridSplitterHeight property. This dependency property
- /// indicates height of grid splitters.
- /// </summary>
- public double GridSplitterHeight
- {
- get { return (double)GetValue(GridSplitterHeightProperty); }
- set { SetValue(GridSplitterHeightProperty, value); }
- }
- #endregion
- internal void _ExecuteContentActivateCommand(LayoutContent content)
- {
- content.IsActive = true;
- }
- #region DocumentPaneMenuItemHeaderTemplate
- /// <summary>
- /// DocumentPaneMenuItemHeaderTemplate Dependency Property
- /// </summary>
- public static readonly DependencyProperty DocumentPaneMenuItemHeaderTemplateProperty =
- DependencyProperty.Register("DocumentPaneMenuItemHeaderTemplate", typeof(DataTemplate), typeof(DockingManager),
- new FrameworkPropertyMetadata((DataTemplate)null,
- new PropertyChangedCallback(OnDocumentPaneMenuItemHeaderTemplateChanged),
- new CoerceValueCallback(CoerceDocumentPaneMenuItemHeaderTemplateValue)));
- /// <summary>
- /// Gets or sets the DocumentPaneMenuItemHeaderTemplate property. This dependency property
- /// indicates the header template to use while creating menu items for the document panes.
- /// </summary>
- public DataTemplate DocumentPaneMenuItemHeaderTemplate
- {
- get { return (DataTemplate)GetValue(DocumentPaneMenuItemHeaderTemplateProperty); }
- set { SetValue(DocumentPaneMenuItemHeaderTemplateProperty, value); }
- }
- /// <summary>
- /// Handles changes to the DocumentPaneMenuItemHeaderTemplate property.
- /// </summary>
- private static void OnDocumentPaneMenuItemHeaderTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((DockingManager)d).OnDocumentPaneMenuItemHeaderTemplateChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the DocumentPaneMenuItemHeaderTemplate property.
- /// </summary>
- protected virtual void OnDocumentPaneMenuItemHeaderTemplateChanged(DependencyPropertyChangedEventArgs e)
- {
- }
- /// <summary>
- /// Coerces the DocumentPaneMenuItemHeaderTemplate value.
- /// </summary>
- private static object CoerceDocumentPaneMenuItemHeaderTemplateValue(DependencyObject d, object value)
- {
- if (value != null &&
- d.GetValue(DocumentPaneMenuItemHeaderTemplateSelectorProperty) != null)
- return null;
- if (value == null)
- return d.GetValue(DocumentHeaderTemplateProperty);
- return value;
- }
- #endregion
- #region DocumentPaneMenuItemHeaderTemplateSelector
- /// <summary>
- /// DocumentPaneMenuItemHeaderTemplateSelector Dependency Property
- /// </summary>
- public static readonly DependencyProperty DocumentPaneMenuItemHeaderTemplateSelectorProperty =
- DependencyProperty.Register("DocumentPaneMenuItemHeaderTemplateSelector", typeof(DataTemplateSelector), typeof(DockingManager),
- new FrameworkPropertyMetadata((DataTemplateSelector)null,
- new PropertyChangedCallback(OnDocumentPaneMenuItemHeaderTemplateSelectorChanged),
- new CoerceValueCallback(CoerceDocumentPaneMenuItemHeaderTemplateSelectorValue)));
- /// <summary>
- /// Gets or sets the DocumentPaneMenuItemHeaderTemplateSelector property. This dependency property
- /// indicates the data template selector to use for the menu items show when user select the DocumentPane document switch context menu.
- /// </summary>
- public DataTemplateSelector DocumentPaneMenuItemHeaderTemplateSelector
- {
- get { return (DataTemplateSelector)GetValue(DocumentPaneMenuItemHeaderTemplateSelectorProperty); }
- set { SetValue(DocumentPaneMenuItemHeaderTemplateSelectorProperty, value); }
- }
- /// <summary>
- /// Handles changes to the DocumentPaneMenuItemHeaderTemplateSelector property.
- /// </summary>
- private static void OnDocumentPaneMenuItemHeaderTemplateSelectorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((DockingManager)d).OnDocumentPaneMenuItemHeaderTemplateSelectorChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the DocumentPaneMenuItemHeaderTemplateSelector property.
- /// </summary>
- protected virtual void OnDocumentPaneMenuItemHeaderTemplateSelectorChanged(DependencyPropertyChangedEventArgs e)
- {
- if (e.NewValue != null &&
- DocumentPaneMenuItemHeaderTemplate != null)
- DocumentPaneMenuItemHeaderTemplate = null;
- }
- /// <summary>
- /// Coerces the DocumentPaneMenuItemHeaderTemplateSelector value.
- /// </summary>
- private static object CoerceDocumentPaneMenuItemHeaderTemplateSelectorValue(DependencyObject d, object value)
- {
- return value;
- }
- #endregion
- #region IconContentTemplate
- /// <summary>
- /// IconContentTemplate Dependency Property
- /// </summary>
- public static readonly DependencyProperty IconContentTemplateProperty =
- DependencyProperty.Register("IconContentTemplate", typeof(DataTemplate), typeof(DockingManager),
- new FrameworkPropertyMetadata((DataTemplate)null));
- /// <summary>
- /// Gets or sets the IconContentTemplate property. This dependency property
- /// indicates the data template to use while extracting the icon from model.
- /// </summary>
- public DataTemplate IconContentTemplate
- {
- get { return (DataTemplate)GetValue(IconContentTemplateProperty); }
- set { SetValue(IconContentTemplateProperty, value); }
- }
- #endregion
- #region IconContentTemplateSelector
- /// <summary>
- /// IconContentTemplateSelector Dependency Property
- /// </summary>
- public static readonly DependencyProperty IconContentTemplateSelectorProperty =
- DependencyProperty.Register("IconContentTemplateSelector", typeof(DataTemplateSelector), typeof(DockingManager),
- new FrameworkPropertyMetadata((DataTemplateSelector)null));
- /// <summary>
- /// Gets or sets the IconContentTemplateSelector property. This dependency property
- /// indicates data template selector to use while selecting the datatamplate for content icons.
- /// </summary>
- public DataTemplateSelector IconContentTemplateSelector
- {
- get { return (DataTemplateSelector)GetValue(IconContentTemplateSelectorProperty); }
- set { SetValue(IconContentTemplateSelectorProperty, value); }
- }
- #endregion
- #region LayoutItems
- List<LayoutItem> _layoutItems = new List<LayoutItem>();
- bool _suspendLayoutItemCreation = false;
- void DetachLayoutItems()
- {
- if (Layout != null)
- {
- _layoutItems.ForEach<LayoutItem>(i => i.Detach());
- _layoutItems.Clear();
- Layout.ElementAdded -= new EventHandler<LayoutElementEventArgs>(Layout_ElementAdded);
- Layout.ElementRemoved -= new EventHandler<LayoutElementEventArgs>(Layout_ElementRemoved);
- }
- }
- void Layout_ElementRemoved(object sender, LayoutElementEventArgs e)
- {
- if (_suspendLayoutItemCreation)
- return;
- CollectLayoutItemsDeleted();
- }
- void Layout_ElementAdded(object sender, LayoutElementEventArgs e)
- {
- if (_suspendLayoutItemCreation)
- return;
- foreach (var content in Layout.Descendents().OfType<LayoutContent>())
- {
- if (content is LayoutDocument)
- CreateDocumentLayoutItem(content as LayoutDocument);
- else //if (content is LayoutAnchorable)
- CreateAnchorableLayoutItem(content as LayoutAnchorable);
- }
- CollectLayoutItemsDeleted();
- }
- DispatcherOperation _collectLayoutItemsOperations = null;
- void CollectLayoutItemsDeleted()
- {
- if (_collectLayoutItemsOperations != null)
- return;
- _collectLayoutItemsOperations = Dispatcher.BeginInvoke(new Action(() =>
- {
- _collectLayoutItemsOperations = null;
- foreach (var itemToRemove in _layoutItems.Where(item => item.LayoutElement.Root != Layout).ToArray())
- {
- if (itemToRemove != null &&
- itemToRemove.Model != null &&
- itemToRemove.Model is UIElement)
- {
- //((ILogicalChildrenContainer)this).InternalRemoveLogicalChild(itemToRemove.Model as UIElement);
- }
- itemToRemove.Detach();
- _layoutItems.Remove(itemToRemove);
- }
- }));
- }
- void AttachLayoutItems()
- {
- if (Layout != null)
- {
- foreach (var document in Layout.Descendents().OfType<LayoutDocument>().ToArray())
- {
- CreateDocumentLayoutItem(document);
- //var documentItem = new LayoutDocumentItem();
- //documentItem.Attach(document);
- //ApplyStyleToLayoutItem(documentItem);
- //_layoutItems.Add(documentItem);
- }
- foreach (var anchorable in Layout.Descendents().OfType<LayoutAnchorable>().ToArray())
- {
- CreateAnchorableLayoutItem(anchorable);
- //var anchorableItem = new LayoutAnchorableItem();
- //anchorableItem.Attach(anchorable);
- //ApplyStyleToLayoutItem(anchorableItem);
- //_layoutItems.Add(anchorableItem);
- }
- Layout.ElementAdded += new EventHandler<LayoutElementEventArgs>(Layout_ElementAdded);
- Layout.ElementRemoved += new EventHandler<LayoutElementEventArgs>(Layout_ElementRemoved);
- }
- }
- void ApplyStyleToLayoutItem(LayoutItem layoutItem)
- {
- layoutItem._ClearDefaultBindings();
- if (LayoutItemContainerStyle != null)
- layoutItem.Style = LayoutItemContainerStyle;
- else if (LayoutItemContainerStyleSelector != null)
- layoutItem.Style = LayoutItemContainerStyleSelector.SelectStyle(layoutItem.Model, layoutItem);
- layoutItem._SetDefaultBindings();
- }
- void CreateAnchorableLayoutItem(LayoutAnchorable contentToAttach)
- {
- if (_layoutItems.Any(item => item.LayoutElement == contentToAttach))
- return;
- var layoutItem = new LayoutAnchorableItem();
- layoutItem.Attach(contentToAttach);
- ApplyStyleToLayoutItem(layoutItem);
- _layoutItems.Add(layoutItem);
- if (contentToAttach != null &&
- contentToAttach.Content != null &&
- contentToAttach.Content is UIElement)
- {
- InternalAddLogicalChild(contentToAttach.Content);
- }
- }
- void CreateDocumentLayoutItem(LayoutDocument contentToAttach)
- {
- if (_layoutItems.Any(item => item.LayoutElement == contentToAttach))
- return;
- var layoutItem = new LayoutDocumentItem();
- layoutItem.Attach(contentToAttach);
- ApplyStyleToLayoutItem(layoutItem);
- _layoutItems.Add(layoutItem);
- if (contentToAttach != null &&
- contentToAttach.Content != null &&
- contentToAttach.Content is UIElement)
- {
- InternalAddLogicalChild(contentToAttach.Content);
- }
- }
- #region LayoutItemContainerStyle
- /// <summary>
- /// LayoutItemContainerStyle Dependency Property
- /// </summary>
- public static readonly DependencyProperty LayoutItemContainerStyleProperty =
- DependencyProperty.Register("LayoutItemContainerStyle", typeof(Style), typeof(DockingManager),
- new FrameworkPropertyMetadata((Style)null,
- new PropertyChangedCallback(OnLayoutItemContainerStyleChanged)));
- /// <summary>
- /// Gets or sets the LayoutItemContainerStyle property. This dependency property
- /// indicates the style to apply to LayoutDocumentItem objects. A LayoutDocumentItem object is created when a new LayoutDocument is created inside the current Layout.
- /// </summary>
- public Style LayoutItemContainerStyle
- {
- get { return (Style)GetValue(LayoutItemContainerStyleProperty); }
- set { SetValue(LayoutItemContainerStyleProperty, value); }
- }
- /// <summary>
- /// Handles changes to the LayoutItemContainerStyle property.
- /// </summary>
- private static void OnLayoutItemContainerStyleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((DockingManager)d).OnLayoutItemContainerStyleChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the LayoutItemContainerStyle property.
- /// </summary>
- protected virtual void OnLayoutItemContainerStyleChanged(DependencyPropertyChangedEventArgs e)
- {
- AttachLayoutItems();
- }
- #endregion
- #region LayoutItemContainerStyleSelector
- /// <summary>
- /// LayoutItemContainerStyleSelector Dependency Property
- /// </summary>
- public static readonly DependencyProperty LayoutItemContainerStyleSelectorProperty =
- DependencyProperty.Register("LayoutItemContainerStyleSelector", typeof(StyleSelector), typeof(DockingManager),
- new FrameworkPropertyMetadata((StyleSelector)null,
- new PropertyChangedCallback(OnLayoutItemContainerStyleSelectorChanged)));
- /// <summary>
- /// Gets or sets the LayoutItemContainerStyleSelector property. This dependency property
- /// indicates style selector of the LayoutDocumentItemStyle.
- /// </summary>
- public StyleSelector LayoutItemContainerStyleSelector
- {
- get { return (StyleSelector)GetValue(LayoutItemContainerStyleSelectorProperty); }
- set { SetValue(LayoutItemContainerStyleSelectorProperty, value); }
- }
- /// <summary>
- /// Handles changes to the LayoutItemContainerStyleSelector property.
- /// </summary>
- private static void OnLayoutItemContainerStyleSelectorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((DockingManager)d).OnLayoutItemContainerStyleSelectorChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the LayoutItemContainerStyleSelector property.
- /// </summary>
- protected virtual void OnLayoutItemContainerStyleSelectorChanged(DependencyPropertyChangedEventArgs e)
- {
- AttachLayoutItems();
- }
- #endregion
- /// <summary>
- /// Return the LayoutItem wrapper for the content passed as argument
- /// </summary>
- /// <param name="content">LayoutContent to search</param>
- /// <returns>Either a LayoutAnchorableItem or LayoutDocumentItem which contains the LayoutContent passed as argument</returns>
- public LayoutItem GetLayoutItemFromModel(LayoutContent content)
- {
- return _layoutItems.FirstOrDefault(item => item.LayoutElement == content);
- }
- #endregion
- #region NavigatorWindow
- NavigatorWindow _navigatorWindow = null;
- void ShowNavigatorWindow()
- {
- if (_navigatorWindow == null)
- {
- _navigatorWindow = new NavigatorWindow(this)
- {
- Owner = Window.GetWindow(this),
- WindowStartupLocation = WindowStartupLocation.CenterOwner
- };
- }
- _navigatorWindow.ShowDialog();
- _navigatorWindow = null;
- Trace.WriteLine("ShowNavigatorWindow()");
- }
- bool IsNavigatorWindowActive
- {
- get { return _navigatorWindow != null; }
- }
- protected override void OnPreviewKeyDown(KeyEventArgs e)
- {
- Trace.WriteLine(string.Format("OnPreviewKeyDown({0})", e.Key));
- if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
- {
- if (e.IsDown && e.Key == Key.Tab)
- {
- if (!IsNavigatorWindowActive)
- {
- ShowNavigatorWindow();
- e.Handled = true;
- }
- }
- }
- base.OnPreviewKeyDown(e);
- }
- #endregion
- #region ShowSystemMenu
- /// <summary>
- /// ShowSystemMenu Dependency Property
- /// </summary>
- public static readonly DependencyProperty ShowSystemMenuProperty =
- DependencyProperty.Register("ShowSystemMenu", typeof(bool), typeof(DockingManager),
- new FrameworkPropertyMetadata((bool)true));
- /// <summary>
- /// Gets or sets the ShowSystemMenu property. This dependency property
- /// indicates if floating windows should show the system menu when a custom context menu is not defined.
- /// </summary>
- public bool ShowSystemMenu
- {
- get { return (bool)GetValue(ShowSystemMenuProperty); }
- set { SetValue(ShowSystemMenuProperty, value); }
- }
- #endregion
- #region AllowMixedOrientation
- /// <summary>
- /// AllowMixedOrientation Dependency Property
- /// </summary>
- public static readonly DependencyProperty AllowMixedOrientationProperty =
- DependencyProperty.Register("AllowMixedOrientation", typeof(bool), typeof(DockingManager),
- new FrameworkPropertyMetadata((bool)false));
- /// <summary>
- /// Gets or sets the AllowMixedOrientation property. This dependency property
- /// indicates if the manager should allow mixed orientation for document panes.
- /// </summary>
- public bool AllowMixedOrientation
- {
- get { return (bool)GetValue(AllowMixedOrientationProperty); }
- set { SetValue(AllowMixedOrientationProperty, value); }
- }
- #endregion
- }
- }
|