因为不存在已打开的单元"

问题描述

WPF 无法关闭撤消单元,因为不存在已打开的单元

XAML代码:

<DataGridTextColumn Width="100"
                                Binding="{Binding SalePrice,
                                                  Mode=TwoWay,
                                                  UpdateSourceTrigger=PropertyChanged,
                                                  StringFormat={0:0.00}}"
                                Header="销售价">
                <DataGridTextColumn.HeaderTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="销售价" VerticalAlignment="Center" FontSize="14" FontWeight="Bold"></TextBlock>
                            <Button x:Name="btnEditSalePrice" ToolTip="设置销售价倍率" Click="btnEditPrice_Click">
                                <Button.Content>
                                    <Image Source="/NaHuo_KDB_WPF;component/Image/header_edit.png" Stretch="None"/>
                                </Button.Content>
                            </Button>
                        </StackPanel>
                    </DataTemplate>
                </DataGridTextColumn.HeaderTemplate>
                <DataGridTextColumn.ElementStyle>
                    <Style TargetType="{x:Type TextBlock}">
                        <Setter Property="HorizontalAlignment" Value="Center" />
                    </Style>
                </DataGridTextColumn.ElementStyle>
            </DataGridTextColumn>

后台cs代码:

private double _salePrice
public double SalePrice
{
    get { return _salePrice; }
    set { _salePrice = value; NotifyPropertyChanged("SalePrice"); }
}

public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(String info)
{
    if (PropertyChanged != null)
    {
        PropertyChanged(this, new PropertyChangedEventArgs(info));
    }
}

以上代码,在编辑DataGrid的“销售价”这一列数据时,在Windows7、Windows8系统下运行没任何问题,但是在Windows XP下运行,部分机子会报错,报错信息如下:

System.InvalidOperationException: Cannot close undo unit because no opened unit exists.
at MS.Internal.Documents.UndoManager.Close(IParentUndoUnit unit, UndoCloseAction closeAction)
at System.Windows.Documents.ImmComposition.CloseCompositionUndoUnit(UndoCloseAction undoCloseAction, ITextPointer compositionEnd)
at System.Windows.Documents.ImmComposition.UpdateCompositionText(FrameworkTextComposition composition, Int32 resultLength, Boolean includeResultText, ITextPointer& start, ITextPointer& end)
at System.Windows.Documents.ImmComposition.RaiseTextInputStartEvent(FrameworkTextComposition composition, Int32 resultLength, String compositionString)
at System.Windows.Documents.ImmComposition.OnWmImeChar(IntPtr wParam, Boolean& handled)
at System.Windows.Documents.ImmComposition.ImmCompositionFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.PublicHooksFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& 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.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.HwndSubclass.DefWndProcWrapper(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Window.ShowHelper(Object booleanBox)
at System.Windows.Window.Show()
at System.Windows.Window.ShowDialog()
at NaHuo_KDB_WPF.Part.PurOrderList.新增_Click(Object sender, RoutedEventArgs e)
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 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& handled)
at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& 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& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
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 NaHuo_KDB_WPF.App.Main()

好纠结的问题,希望大神们都来帮帮忙,谢谢!

解决方案

确实是这样啊`enter code herenter code hereeenter code herenter code hereeenter code herenter code heree

时间: 2024-09-12 01:50:17

因为不存在已打开的单元&quot;的相关文章

textbox-WPF项目 错误信息“无法关闭单元,因为不存在已打开的单元”,求大神支招

问题描述 WPF项目 错误信息"无法关闭单元,因为不存在已打开的单元",求大神支招 DataGrid其中一列里的TextBox,这个TextBox有值转换,对输入也做了限制,允许输入数字和"="."-".用回车切换焦点,到这一列输入除字母和数字之外的字符就会报出这个错误.代码调试不出错误,所有代码都走完之后会报出这个错误.而且是有些电脑运行不出错,有些就出错. 解决方案 请附代码,看下具体在哪里报错

.net连接SQLSERVER数据库,网页上不停的刷新就报错&amp;amp;quot;ExecuteScalar 要求已打开且可用的连接。连接的当前状态为打开。&amp;amp;quot;

问题描述 .net连接SQLSERVER数据库,网页上定时刷新就报错"ExecuteScalar要求已打开且可用的连接.连接的当前状态为打开."实在找不出问题出在哪了,请大家帮帮忙吧"/Web"应用程序中的服务器错误.--------------------------------------------------------------------------------ExecuteScalar要求已打开且可用的连接.连接的当前状态为打开.说明:执行当前Web

如何获得已打开目录的目录句柄?

问题描述 如何获得已打开目录的目录句柄? 我想用ReadDirectoryChangesW()来获取文件操作信息,但是其中的一个参数是监控目录的句柄,都说用createfile函数来得到目录的句柄,但是如果是已经用鼠标打开的目录,又该怎样获得其句柄呢? 解决方案 你用CreateFile()一样可以获取到对应的句柄,用共享读的方式等,用鼠标打开,不会影响

数据库xxx已打开,并且一次只能有一个用户访问。 (Microsoft SQL Server,错误: 924)

操作数据库失败,提示如下错误: 数据库xxx已打开,并且一次只能有一个用户访问. (Microsoft SQL Server,错误: 924) 重启数据库问题仍然存在.可执行以下sql解决: USE master; GODECLARE @SQL VARCHAR(MAX); SET @SQL='' SELECT @SQL=@SQL+'; KILL '+RTRIM(SPID) FROM master..sysprocesses WHERE dbid=DB_ID('库名'); EXEC(@SQL);

javascript-js如何实现点击链接激活已打开页面?

问题描述 js如何实现点击链接激活已打开页面? 具体就是如果a页面已经打开,再点击b页面上a页面的链接,不是再新打开一个页面而是激活已打开的a页面.应该如何实现?谢谢- 解决方案 不要用页面,用弹出层模拟.因为不同的页面比较难以通讯.非要用,需要借助websocket传参数.

快捷键-sublime编辑器_如何从已打开文件中查询指定字符

问题描述 sublime编辑器_如何从已打开文件中查询指定字符 sublime编辑器_如何从已打开文件中查询指定字符? 如我在初始化文件中加入了session_start,避免以前开发过程中已经写过session_start()函数出现重复,需要删除.但挨个找显得特麻烦. 问:如何实现快速查找?如果只可以,请分享整套的查找技巧,当然,最好包括我在上面提到的问题. PS:已经百度了一下,暂未找到相关的内容,故来提问,请大虾小虾们帮帮忙!TKS

sqlconnection-executereader 要求已打开并可用的connection

问题描述 executereader 要求已打开并可用的connection private void button1_Click(object sender, EventArgs e) { SqlHelper.con.Open(); //这个是自己写的类 //里面就两句话 ( public static string connstring = "Data Source=.;Initial Catalog=students;Persist Security Info=True;User ID=s

excel 进程-获取已打开多个的EXCEL操作

问题描述 获取已打开多个的EXCEL操作 [背景]南方CASS软件打开几千个EXCEL表格(都是新建的,还没保存),它们的特点是:一个excel在进程中表现为一个exccel进程,现在想以第一个工作表作为名称保存所有excel. 使用System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application")只能获取第一个excel进程,于是我遍历进程,处理一个关闭一个,具体代码是: private void b

c# 怎在主窗体中自定一个属性,用来保存已打开的子窗体实例

问题描述 我的目的就是想实现子窗体和子窗体互访,网上有一个方法mdiParent是针对form的,但是我用的是DockPane的DockContent,所以没办法用mdiParent.不知可不可以在主窗体formMain中新建一个属性formCollections,这个属性用来保存已打开的子窗体的实例,每打开一个子窗体,就把这个子窗体的实例作为一个对象加入到主窗体的formCollections属性中,当某一子窗体childForm1想访问另一子窗体childForm2时,就可以运用formMa