This project is read-only.

ArgumentNullException in GetAdornerLayer

Apr 5, 2012 at 7:24 AM

I get an exception, when I call the backstage via KeyTips:

UnhandledException!
System.ArgumentNullException: Der Wert darf nicht NULL sein.
Parametername: element
   bei MS.Internal.Media.VisualTreeUtils.AsNonNullVisual(DependencyObject element, Visual& visual, Visual3D& visual3D)
   bei System.Windows.Media.VisualTreeHelper.GetParent(DependencyObject reference)
   bei Fluent.KeyTipAdorner.GetAdornerLayer(UIElement element) in C:\Daten\APRGX\DotNet\Fluent\Fluent\KeyTipAdorner.cs:Zeile 439.
   bei Fluent.KeyTipAdorner.Attach() in C:\Daten\APRGX\DotNet\Fluent\Fluent\KeyTipAdorner.cs:Zeile 205.
   bei Fluent.KeyTipAdorner.Back() in C:\Daten\APRGX\DotNet\Fluent\Fluent\KeyTipAdorner.cs:Zeile 466.
   bei Fluent.KeyTipAdorner.OnPreviewKeyDown(Object sender, KeyEventArgs e) in C:\Daten\APRGX\DotNet\Fluent\Fluent\KeyTipAdorner.cs:Zeile 351.
   bei System.Windows.Input.KeyEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   bei System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   bei System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   bei System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   bei System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   bei System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
   bei System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
   bei System.Windows.Input.InputManager.ProcessStagingArea()
   bei System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
   bei System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
   bei System.Windows.Interop.HwndKeyboardInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawKeyboardActions actions, Int32 scanCode, Boolean isExtendedKey, Boolean isSystemKey, Int32 virtualKey)
   bei System.Windows.Interop.HwndKeyboardInputProvider.ProcessKeyAction(MSG& msg, Boolean& handled)
   bei System.Windows.Interop.HwndSource.CriticalTranslateAccelerator(MSG& msg, ModifierKeys modifiers)
   bei System.Windows.Interop.HwndSource.OnPreprocessMessage(Object param)
   bei System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   bei MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
   bei System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   bei System.Windows.Interop.HwndSource.OnPreprocessMessageThunk(MSG& msg, Boolean& handled)
   bei System.Windows.Interop.HwndSource.WeakEventPreprocessMessage.OnPreprocessMessage(MSG& msg, Boolean& handled)
   bei System.Windows.Interop.ComponentDispatcherThread.RaiseThreadMessage(MSG& msg)
   bei System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   bei System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   bei System.Windows.Application.RunDispatcher(Object ignore)
   bei System.Windows.Application.RunInternal(Window window)
   bei System.Windows.Application.Run(Window window)
   bei System.Windows.Application.Run()
   bei FluentRibbonTest.App.Main() in C:\mist\Spielwiese\FluentRibbonTest\obj\x86\Debug\App.g.cs:Zeile 0.
   bei System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   bei System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   bei System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   bei System.Threading.ThreadHelper.ThreadStart()

Here is my sample window:

<Fluent:RibbonWindow x:Class="FluentRibbonTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Fluent="clr-namespace:Fluent;assembly=Fluent"
    xmlns:System="clr-namespace:System;assembly=mscorlib" 
        Title="MainWindow" Height="600" Width="800">
    <DockPanel>
        <Fluent:Ribbon x:Name="ribbon" DockPanel.Dock="Top">
            <Fluent:Ribbon.Menu>
                <Fluent:Backstage>
                    <Fluent:BackstageTabControl>
                        <Fluent:BackstageTabItem Header="New" Fluent:KeyTip.Keys="N">
                            <StackPanel>
                                <Fluent:Button Command="New" Fluent:KeyTip.Keys="N" CommandTarget="{Binding ElementName=ribbon}">New</Fluent:Button>
                                <Fluent:Button Header="Open..." Fluent:KeyTip.Keys="O" Command="Open" CommandTarget="{Binding ElementName=ribbon}" />
                                <Fluent:Button Header="Save as..." Fluent:KeyTip.Keys="A" Command="SaveAs" CommandTarget="{Binding ElementName=ribbon}" />
                            </StackPanel>
                        </Fluent:BackstageTabItem>
                        <Fluent:BackstageTabItem Header="Print"/>
                        <Fluent:Button Header="Blue" Icon="Images\Blue.png"></Fluent:Button>
                        <Button Command="New">Product</Button>
                        <Fluent:Button Command="New">Product</Fluent:Button>
                    </Fluent:BackstageTabControl>
                </Fluent:Backstage>
            </Fluent:Ribbon.Menu>
            <Fluent:RibbonTabItem>
            </Fluent:RibbonTabItem>
        </Fluent:Ribbon>
        <Grid>
            <Viewbox >
                <TextBlock>Text to display</TextBlock>
            </Viewbox>
        </Grid>
    </DockPanel>
</Fluent:RibbonWindow>

You can reproduce the error by pressing Alt,d,n,ESC on german PC or Alt,f,n,ESC on english PC respectivly.

GetAdornerLayer doesn't check for the parents to be null. I tried to add a check for null in GetAdornerLayer and in the calling function Attach, but though the exception was gone, the behavior is something strange. So I don't know a correct solution.

May 25, 2012 at 3:13 PM

As I didn't get any answer by now...

Am I the only one getting this exception?

Or do you need any more information to reproduce?

May 25, 2012 at 7:32 PM

Hi,

I can reproduce your error, but I have no solution for the problem so far.

Igor