选项卡或取消选择不提交数据的单元格

发布于 2024-08-02 21:39:03 字数 280 浏览 1 评论 0原文

我正在使用 WPF 工具包 DataGrid,目前在将数据提交回源时遇到问题。

我的网格绑定到 CLR 对象列表,并且我有一个转换器,同时实现了转换和转换回方法。

如果用户在单元格中按 Enter 键,则两种方式绑定工作正常,但如果取消选择或按 Tab 键退出单元格,则键入的数据将丢失。

我对 CellEditEnding 事件进行了中断,Tab 和 Enter 的两个事件看起来相同,但是当它到达我的转换器上的 ConvertBack 方法时,该值是空的。

任何帮助将不胜感激。

I am working with the the WPF Toolkit DataGrid and currently have a problem with committing data back to the source.

My grid is bound to a CLR object list and I have a converter with both the convert and convert back methods implemented.

The two way binding works fine if the user hits Enter in the cells but if they deselect or tab out of the cells the data that was typed is lost.

I have put a break on the CellEditEnding event and both events for Tab and Enter seem identical, but when it gets to the ConvertBack method on my converter the value is empty.

Any help would be much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

宫墨修音 2024-08-09 21:39:03

尝试将控件的 Binding 的 UpdateSourceTrigger 参数更改为 PropertyChanged 而不是默认的 LostFocus。

例如

          <TextBox
            Width="75"
            VerticalAlignment="Top"
            Margin="10"
            Text="{Binding
            Source={StaticResource data},
            Path=Age,
            UpdateSourceTrigger=PropertyChanged,
            ValidatesOnDataErrors=True,
            ValidatesOnExceptions=True}"
            Style="{StaticResource textBoxInError}" />

Try changing the UpdateSourceTrigger parameter of your control's Binding to PropertyChanged instead of the default LostFocus.

Eg

          <TextBox
            Width="75"
            VerticalAlignment="Top"
            Margin="10"
            Text="{Binding
            Source={StaticResource data},
            Path=Age,
            UpdateSourceTrigger=PropertyChanged,
            ValidatesOnDataErrors=True,
            ValidatesOnExceptions=True}"
            Style="{StaticResource textBoxInError}" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文