需要将焦点保持在 wpf 内容面板中
我在运行模式下切换 ListViewItem
的内容模板以启用编辑项目。为此,我显示了一个带有“确定”和“取消”选项的面板
,我需要用户在移动到另一个项目之前选择其中任何一个选项。我希望该 Panel
表现得像模态 Dialog
。 有什么建议吗?
高级感谢, 达斯
I am switching content template of a ListViewItem
at run mode to enable editting the item. For that I am showing a Panel
with Ok and Cancel options and I need the user to select any of those option before moving to anotheritem. I want that Panel
to behave like a modal Dialog
.
Any suggestions?
Advanced Thanks,
Das
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试收听 PreviewLostKeyboardFocus 事件并当您不想让焦点离开时,将其标记为已处理。这是一个例子。我们有两列,如果您将焦点放入第一列,则在单击“释放焦点”按钮之前您永远不会离开该列:
XAML
C#
我正在执行一项额外检查确保新的焦点目标是否属于我们的面板。如果我们不这样做,我们永远不会让焦点离开当前聚焦的元素。值得一提的是,这种方法并不能阻止用户点击 UI 中的其他按钮。它只是保持焦点。
希望这有帮助。
干杯,安瓦卡。
You could try listen to PreviewLostKeyboardFocus event and mark it as handled when you don't want to let focus go. Here is an example. We have two columns, and if you put focus into the first column you never go out from it until you click Release Focus button:
XAML
C#
I'm doing one extra check to ensure whether new focus target belongs to our panel. If we don't do this we never let focus leave from the currently focused element. It worth to mention that this approach doesn't keep user from clicking on other buttons in UI. It just holds focus.
Hope this helps.
Cheers, Anvaka.