ButchersBoy / Dragablz

Dragable and tearable tab control for WPF
http://dragablz.net
MIT License
2.17k stars 321 forks source link

Expose an easier way to access Dragablz #212

Open RickStrahl opened 6 years ago

RickStrahl commented 6 years ago

Quite frequently when I need do some thing with the Tab control, I need access to the internals that are not exposed in the Tabablz control. There appears to be no clean way to get access to the underlying DragablzControl or the DragablzItem collections which incidentally are required for some of the public interfaces.

For example, I was trying to work around issue #211 by explicitly accessing the HeaderItemsOrganiser which has a Sort() method that takes a DragablzItem collection. In order to get to that I had to use Reflection to get at the private fields. Yuk :-)

// Original code that breaks due to null error per #211
//headers = TabControl.GetOrderedHeaders();
// Internal implementation of above
//return this._dragablzItemsControl.ItemsOrganiser.Sort(this._dragablzItemsControl.DragablzItems());

// Manually hacking access to this functionality
var control = ReflectionUtils.GetField(TabControl, "_dragablzItemsControl") as DragablzItemsControl;
var ditems = ReflectionUtils.CallMethod(control, "DragablzItems") as List<DragablzItem>;                    
headers = TabControl.HeaderItemsOrganiser?.Sort(ditems);

if (headers == null)
   // alternate behavior

Am I missing some other obvious ways to get at these properties? I'm wondering why these are internal especially since some of the public interfaces require them as parameters.