ActionMessage loses Target when minimizing Ribbon

Topics: Actions & Coroutines
Jan 18, 2012 at 8:55 AM
Edited Jan 18, 2012 at 8:57 AM

Hello,

I have a problem with my Ribbon in my application.

I am building a WPF application which contains a Ribbon, the buttons on this Ribbon are bound to 1 method in the shellview (this is a Conductor.OneActive), the shellview is responsible for locating the workspace which belongs to this button and show it:

ShellViewModel.cs

    [Export(typeof(IShell))]
    public class ShellViewModel : Conductor.Collection.OneActive, IShell
        public void DisplayWorkspace(object dataContext)
        {
            IEnumerable workspacesCollection = WorkspaceFactory.GetWorkspaces(
                    ((IWorkspace)((IButtonData)dataContext).Target).WorkspaceType);
            foreach (IWorkspace workspace in workspacesCollection)
            {
                workspace.Mode = ((IButtonData)dataContext).Mode;
                this._dockWindowManager = IoC.Get();
                this._dockWindowManager.ShowDocumentWindow(workspace);

                NotifyOfPropertyChange(() => IsSaveProgressVisible);
            }
        }

        // More code ...........
   }

 

In the different workspaces I add the buttons to the ribbon with the following code:

        public IGroupData ViewModelGroupData
        {
            get
            {
                Uri smallHelpImage = new Uri("/Test.Resources;component/Images/16x16/Help16.png", UriKind.Relative);
                string helpString = "Press F1 for help..";

                //Button 1
                GroupData newGroup = new GroupData("New", this.IndexOnTab);
                ButtonData addButton = new ButtonData(WorkspaceMode.AddView, "Add Customer", "DisplayWorkspace($this)", this)
                {
                    SmallImage = new Uri("/Test.Resources;component/Images/16x16/Customer16.png", UriKind.Relative),
                    LargeImage = new Uri("/Test.Resources;component/Images/32x32/Customer32.png", UriKind.Relative),

                    KeyTip = "Add Customer",
                    ToolTipTitle = "Add Customer",
                    ToolTipDescription = "Add Customer",
                    ToolTipFooterTitle = helpString,
                    ToolTipFooterImage = smallHelpImage
                };
	}

In the ribbon resources I have the following styles:

    <!-- RibbonControl -->
    <Style x:Key="RibbonControlStyle">
        <Setter Property="ribbon:RibbonControlService.Label" Value="{Binding Label}" />
        <Setter Property="ribbon:RibbonControlService.LargeImageSource" Value="{Binding LargeImage, Converter={StaticResource nullImageConverter}}" />
        <Setter Property="ribbon:RibbonControlService.SmallImageSource" Value="{Binding SmallImage, Converter={StaticResource nullImageConverter}}" />
        <Setter Property="ribbon:RibbonControlService.ToolTipTitle" Value="{Binding ToolTipTitle}" />
        <Setter Property="ribbon:RibbonControlService.ToolTipDescription" Value="{Binding ToolTipDescription}" />
        <Setter Property="ribbon:RibbonControlService.ToolTipImageSource" Value="{Binding ToolTipImage, Converter={StaticResource nullImageConverter}}" />
        <Setter Property="ribbon:RibbonControlService.ToolTipFooterTitle" Value="{Binding ToolTipFooterTitle}"/>
        <Setter Property="ribbon:RibbonControlService.ToolTipFooterDescription" Value="{Binding ToolTipFooterDescription}"/>
        <Setter Property="ribbon:RibbonControlService.ToolTipFooterImageSource" Value="{Binding ToolTipFooterImage, Converter={StaticResource nullImageConverter}}"/>
    </Style>
    
    <!-- RibbonGroup -->
    <Style TargetType="{x:Type ribbon:RibbonGroup}" BasedOn="{StaticResource RibbonControlStyle}">
        <Setter Property="QuickAccessToolBarId" Value="{Binding Label}" />
        <Setter Property="Header" Value="{Binding Label}" />
        <Setter Property="ItemsSource" Value="{Binding ControlDataCollection}" />
    </Style>
    
    <!-- RibbonButton -->
    <DataTemplate DataType="{x:Type rib:ButtonData}">
        <ribbon:RibbonButton />
    </DataTemplate>
    <Style TargetType="{x:Type ribbon:RibbonButton}" BasedOn="{StaticResource RibbonControlStyle}">
        <Setter Property="cal:Action.TargetWithoutContext" Value="{Binding Target}" />
        <Setter Property="cal:Message.Attach" Value="{Binding Message}" />
    </Style>

 

When I launch the application I can show the different workspaces by clicking the ribbon buttons.

The problem is, as soon as I minimize the ribbon and then click on a tab to show the tab with its ribbon buttons and click one of these buttons, an System.Exception is generated stated that "No target is found for DisplayWorkspace"

Using logging I can see that the three buttons on the tab are (re)-attached to a message handler, but I don't know why. If I change the Ribbon back to a normal state and click the button again the DisplayWorkspace function is found and called??

2012-01-18 09:47:00,667 [9] INFO  Caliburn.Micro.ActionMessage - Action: DisplayWorkspace availability update.
2012-01-18 09:47:00,667 [9] INFO  Caliburn.Micro.ActionMessage - Action: DisplayWorkspace availability update.
2012-01-18 09:47:00,667 [9] INFO  Caliburn.Micro.ActionMessage - Action: DisplayWorkspace availability update.
System.Windows.Data Error: 40 : BindingExpression path error: 'IsDropDownOpen' property not found on 'object' ''RibbonContentPresenter' (Name='PART_ContentPresenter')'. BindingExpression:Path=IsDropDownOpen; DataItem='RibbonContentPresenter' (Name='PART_ContentPresenter'); target element is 'RibbonButton' (Name=''); target property is 'NoTarget' (type 'Object')
System.Windows.Data Error: 40 : BindingExpression path error: 'IsDropDownOpen' property not found on 'object' ''RibbonContentPresenter' (Name='PART_ContentPresenter')'. BindingExpression:Path=IsDropDownOpen; DataItem='RibbonContentPresenter' (Name='PART_ContentPresenter'); target element is 'RibbonButton' (Name=''); target property is 'NoTarget' (type 'Object')
System.Windows.Data Error: 40 : BindingExpression path error: 'IsDropDownOpen' property not found on 'object' ''RibbonContentPresenter' (Name='PART_ContentPresenter')'. BindingExpression:Path=IsDropDownOpen; DataItem='RibbonContentPresenter' (Name='PART_ContentPresenter'); target element is 'RibbonButton' (Name=''); target property is 'NoTarget' (type 'Object')
2012-01-18 09:47:03,246 [9] INFO  Caliburn.Micro.Action - Attaching message handler CeerpApp.Workspaces.Customers.Presentation.CustomerViewModel to Microsoft.Windows.Controls.Ribbon.RibbonButton.
2012-01-18 09:47:03,261 [9] INFO  Caliburn.Micro.Action - Attaching message handler CeerpApp.Workspaces.Customers.Presentation.CustomerViewModel to Microsoft.Windows.Controls.Ribbon.RibbonButton.
2012-01-18 09:47:03,261 [9] INFO  Caliburn.Micro.Action - Attaching message handler CeerpApp.Workspaces.Customers.Presentation.CustomerViewModel to Microsoft.Windows.Controls.Ribbon.RibbonButton.
2012-01-18 09:47:03,261 [9] INFO  Caliburn.Micro.ActionMessage - Action: DisplayWorkspace availability update.
2012-01-18 09:47:03,277 [9] INFO  Caliburn.Micro.ActionMessage - Action: DisplayWorkspace availability update.
2012-01-18 09:47:03,277 [9] INFO  Caliburn.Micro.ActionMessage - Action: DisplayWorkspace availability update.
2012-01-18 09:47:03,277 [9] INFO  Caliburn.Micro.ActionMessage - Action: DisplayWorkspace availability update.
2012-01-18 09:47:03,277 [9] INFO  Caliburn.Micro.ActionMessage - Action: DisplayWorkspace availability update.
2012-01-18 09:47:03,277 [9] INFO  Caliburn.Micro.ActionMessage - Action: DisplayWorkspace availability update.
2012-01-18 09:47:15,263 [9] INFO  Caliburn.Micro.ActionMessage - Invoking Action: DisplayWorkspace.
2012-01-18 09:47:15,263 [9] ERROR Caliburn.Micro.ActionMessage - No target found for method DisplayWorkspace.
System.Exception: No target found for method DisplayWorkspace.
A first chance exception of type 'System.Exception' occurred in Caliburn.Micro.dll
A first chance exception of type 'System.Exception' occurred in WindowsBase.dll
System.Transactions Critical: 0 : http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/UnhandledUnhandled exceptionCeerpApp.vshost.exeSystem.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089No target found for method DisplayWorkspace.   at Caliburn.Micro.ActionMessage.Invoke(Object eventArgs) in 
C:\Marcel\caliburnmicro_7fec57e8a1fd\src\Caliburn.Micro.Silverlight\ActionMessage.cs:line 218
   at System.Windows.Interactivity.TriggerBase.InvokeActions(Object parameter)
   at System.Windows.Interactivity.EventTriggerBase.OnEvent(EventArgs eventArgs)
   at System.Windows.Interactivity.EventTriggerBase.OnEventImpl(Object sender, EventArgs eventArgs)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
   at System.Windows.Controls.Primitives.ButtonBase.OnClick()
   at System.Windows.Controls.Button.OnClick()
   at Microsoft.Windows.Controls.Ribbon.RibbonButton.OnClick() in C:\Program Files\Microsoft Ribbon for WPF\MicrosoftRibbonForWPFSourceAndSamples\RibbonControlsLibrary\Microsoft\Windows\Controls\Ribbon\RibbonButton.cs:line 494
   at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
   at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
   at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
   at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
   at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
   at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
   at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
   at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean&amp; handled)
   at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&amp; handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&amp; handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG&amp; msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.Run()
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run(Window window)
   at System.Windows.Application.Run()
   at CeerpApp.App.Main() in E:\Solution 1601\CeerpApp\obj\x86\Debug\App.g.cs:line 0
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()System.Exception: No target found for method DisplayWorkspace.
   at Caliburn.Micro.ActionMessage.Invoke(Object eventArgs) in C:\Marcel\caliburnmicro_7fec57e8a1fd\src\Caliburn.Micro.Silverlight\ActionMessage.cs:line 218
   at System.Windows.Interactivity.TriggerBase.InvokeActions(Object parameter)
   at System.Windows.Interactivity.EventTriggerBase.OnEvent(EventArgs eventArgs)
   at System.Windows.Interactivity.EventTriggerBase.OnEventImpl(Object sender, EventArgs eventArgs)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
   at System.Windows.Controls.Primitives.ButtonBase.OnClick()
   at System.Windows.Controls.Button.OnClick()
   at Microsoft.Windows.Controls.Ribbon.RibbonButton.OnClick() in C:\Program Files\Microsoft Ribbon for WPF\MicrosoftRibbonForWPFSourceAndSamples\RibbonControlsLibrary\Microsoft\Windows\Controls\Ribbon\RibbonButton.cs:line 494
   at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
   at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
   at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
   at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
   at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
   at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
   at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
   at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean&amp; handled)
   at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&amp; handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&amp; handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG&amp; msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.Run()
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run(Window window)
   at System.Windows.Application.Run()
   at CeerpApp.App.Main() in E:\Solution 1601\CeerpApp\obj\x86\Debug\App.g.cs:line 0
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
Can someone explain what's happening here and how I can resolve this.
Thanks 
Marcel
Coordinator
Jan 19, 2012 at 4:18 AM

Can you try the absolute latest code from the repository and see if you see any different behavior?

Jan 23, 2012 at 8:23 AM

@Rob

I tryed the latest version (1.3 RTW) but this does not solve my problem, do you have any other suggestions.

Marcel