带有TextBlock / Hyperlink的WPF TreeView / TreeViewItem崩溃

时间:2015-12-04 21:06:40

标签: c# wpf xaml treeview

可以使用键盘(向上和向下箭头键)导航第一个示例。

<TreeView BorderThickness="0">
    <TreeViewItem>
        <TreeViewItem.Header>
            <TextBlock>Parent</TextBlock>
        </TreeViewItem.Header>
        <TreeViewItem.Items>
            <TreeViewItem>
                <TreeViewItem.Header>
                    <TextBlock>Child</TextBlock>
                </TreeViewItem.Header>
            </TreeViewItem>
        </TreeViewItem.Items>
    </TreeViewItem>
</TreeView>

第二个包含超链接,键盘导航崩溃(向上和向下箭头键)

<TreeView BorderThickness="0">
    <TreeViewItem>
        <TreeViewItem.Header>
            <TextBlock>Parent</TextBlock>
        </TreeViewItem.Header>
        <TreeViewItem.Items>
            <TreeViewItem>
                <TreeViewItem.Header>
                    <TextBlock>
                        <Hyperlink>
                            Child
                        </Hyperlink>
                    </TextBlock>
                </TreeViewItem.Header>
            </TreeViewItem>
        </TreeViewItem.Items>
    </TreeViewItem>
</TreeView>
  

考虑到我对WPF/XAML不熟悉,我做错了什么或我错过了什么?使用VS 2015.1.NET 4.6

例外是:

System.InvalidOperationException: 'System.Windows.Documents.Hyperlink' is not a Visual or Visual3D.

at MS.Internal.Media.VisualTreeUtils.AsVisual(DependencyObject element, Visual&amp; amp; visual, Visual3D&amp;amp; visual3D)
at System.Windows.Media.VisualTreeHelper.GetParent(DependencyObject reference)
at System.Windows.Controls.TreeViewItem.AllowHandleKeyEvent(FocusNavigationDirection direction)
at System.Windows.Controls.TreeViewItem.HandleUpDownKey(Boolean up, KeyEventArgs e)
at System.Windows.Controls.TreeViewItem.OnKeyDown(KeyEventArgs e)
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.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
at System.Windows.Interop.HwndKeyboardInputProvider.ProcessKeyAction(MSG&amp; amp; msg, Boolean&amp;amp; handled)
at System.Windows.Interop.HwndSource.CriticalTranslateAccelerator(MSG&amp; amp; msg, ModifierKeys modifiers)
at System.Windows.Interop.HwndSource.OnPreprocessMessage(Object param)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
at System.Windows.Interop.HwndSource.OnPreprocessMessageThunk(MSG&amp; amp; msg, Boolean&amp;amp; handled)
at System.Windows.Interop.ComponentDispatcherThread.RaiseThreadMessage(MSG&amp; amp; msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)

Microsoft Connect上添加了错误报告。谁知道......

0 个答案:

没有答案