WPF:Automation.Peers.ItemAutomationPeer.GetNameCore中的NullReferenceException

时间:2017-08-01 09:54:45

标签: wpf automation nullreferenceexception

我有一个烦恼的问题并花了一整天的时间,但仍然无法修复它。 我在WPF UI上有一个按钮,它用于向treeview添加项目,xaml中的代码如下:

<Button Content="Create Item"  
                                        Command="{Binding NewItem}"
                                        Click="NewItemButton_Click"
                                        TabIndex="16"                                                                                           
                                        ToolTip="{Binding NewItemHelpText}"
                                        ToolTipService.ShowOnDisabled="True">
                                        <Button.IsEnabled>
                                            <MultiBinding Converter="{StaticResource LogicalAndConverter}">
                                                <Binding Path="CurrentItem" Converter="{StaticResource ItemCreationConverter}"/>
                                                <Binding Path="ControlMode" Converter="{StaticResource MyConverter}" ConverterParameter="{x:Static local:Option.ReadOnly}"/>
                                            </MultiBinding>
                                        </Button.IsEnabled>
                                    </Button>

有时,点击此按钮后会抛出异常,

> ERROR MyApplication.App [(null)] - Error in MyApplication
   System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Windows.Automation.Peers.ItemAutomationPeer.GetNameCore()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdatePeer(Object arg)
   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)

这个异常随机抛出,在添加一些日志来调试代码后,我发现NewItemButton_Click事件和NewItem命令都执行到最后,我搜索我的工作解决方案,没有找到任何关于自动化的信息,我不知道这个例外抛出的原因和原因。

有人能帮助我吗?感谢。

0 个答案:

没有答案