Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Need to know the current DockItem at all times. (Read 3963 times)
MavinTech
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 19
Joined: Jul 30th, 2020
Need to know the current DockItem at all times.
Dec 23rd, 2020 at 4:18pm
Print Post  
Looking for an event that can fire when a DockControl's DockItem is selected.  I tried GotFocus, but it didn't happen when I clicked on a tab of a tabbed Item.  Was hoping for a DockControl_OnSelectionChanged type of event.

I basically need to know what the "current" DockItem is within the DockControl as the user selects various items.

Also, is there a way to prevent a user from closing/hiding an item.
  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3374
Joined: Oct 19th, 2005
Re: Need to know the current DockItem at all times.
Reply #1 - Dec 28th, 2020 at 2:43pm
Print Post  
There's the SelectedItem property in DockWindowBase (from which e.g. TabbedDocument and DockWindow derive). I can't see any event raised when it changes, maybe try binding your own property to it to get notified when it gets set, or see second answer here -

https://stackoverflow.com/questions/4764916/listen-to-changes-of-dependency-prop...

We'll have in mind adding some global event in DockControl for next release.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
MavinTech
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 19
Joined: Jul 30th, 2020
Re: Need to know the current DockItem at all times.
Reply #2 - Dec 28th, 2020 at 4:20pm
Print Post  
Tried to set this up with the UI.DockControl sample code supplied with the WPFPack and I'm getting lost.  Would you be able to throw together some sample code based on that sample code?

My current need is a two sided document (front and back) where each side is a diagram control inside a DockItem.
  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3374
Joined: Oct 19th, 2005
Re: Need to know the current DockItem at all times.
Reply #3 - Dec 29th, 2020 at 2:25pm
Print Post  
E.g. this will detect active tab changes in the TabbedDocument:

Code
Select All
var tabDoc = dockControl.Items.OfType<TabbedDocument>().FirstOrDefault();
if (tabDoc != null)
{
    SetBinding(
            SelectedItemProperty,
            new Binding
            {
                Source = tabDoc,
                Path = new PropertyPath(DockWindowBase.SelectedItemProperty),
                Mode = BindingMode.OneWay
            });
}

DependencyProperty SelectedItemProperty = DependencyProperty.Register(
    "SelectedItem", typeof(DockItem), typeof(Window1),
    new PropertyMetadata(OnSelectedItemChanged));

static void OnSelectedItemChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
    var dockItem = (DockItem)e.NewValue;
    Debug.WriteLine("OnSelectedItemChanged: " + dockItem.Content);
} 



Anyway we should have an event for this early next year Wink

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
MavinTech
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 19
Joined: Jul 30th, 2020
Re: Need to know the current DockItem at all times.
Reply #4 - Dec 29th, 2020 at 3:28pm
Print Post  
I will incorporate this into my code.  Thanks for the help.

For the added feature coming, it would be very useful to include selection of any DockItem within the DockControl? (DockWindow item, floating, autohidden, etc...).

Thanks again.
  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3374
Joined: Oct 19th, 2005
Re: Need to know the current DockItem at all times.
Reply #5 - Dec 30th, 2020 at 3:50pm
Print Post  
Quote:
Also, is there a way to prevent a user from closing/hiding an item.


This build adds ItemClosing validation event -
https://mindfusion.eu/_temp/dock_closing.zip

Code
Select All
void dockControl_ItemClosing(object sender, ItemValidationEventArgs e)
{
    if (MessageBox.Show(
        "Are you sure you want to close unsaved document?",
        "Document changed", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
    {
        e.Cancel = true;
    }
} 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3374
Joined: Oct 19th, 2005
Re: Need to know the current DockItem at all times.
Reply #6 - Jan 8th, 2021 at 7:49am
Print Post  
New build adds ItemSelected event -
https://mindfusion.eu/_temp/dock_closing.zip

Regards,
Slavcho
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint