WPF 复合应用程序 - 选项卡区域 - 视图未获得焦点

发布于 2024-07-22 11:19:04 字数 378 浏览 5 评论 0原文

我刚刚开始使用 WPF 的复合应用程序库。 在我的 shell 中,我在选项卡控件中有一个区域,用于显示不同类型的视图。 我还有一个工具栏,其中的按钮连接到命令,例如保存。 命令绑定在我的视图中,并且视图具有 canExecute 和execute 方法。

这个想法是,当我单击选项卡时,应根据视图中的方法启用或禁用我的工具栏按钮。 问题是当我切换选项卡时,视图没有获得焦点,并且该视图的 canExecute 没有被调用。 工具栏按钮仍然连接到先前选择的视图中的命令,并以这种方式提醒,直到我实际单击新视图为止,

我现在很难理解如何强制视图获得焦点。 我尝试在选项卡 SelectionChanged 时查看选项卡的内容并在那里设置焦点,但它没有产生任何影响。 有任何想法吗?

I'm just starting to use the composite application libraries for WPF. In my shell I have a region in a tabcontrol that is used to display different types of views. I also have a toolbar with buttons hooked up to commands, for example save. The commands are bound in my views, and the views have the canExecute and execute methods.

The idea is that when i click a tab, my tool bar buttons should be enabled or disabled according to the methods in the view. Problem is when I switch tabs the view is not getting the focus and the canExecute for that view doesn't get called. The toolbar buttons remain connected to the commands in the previously selected view, and reminds that way until i actually click on the new view

I'm stumped right now on how to force the view to get the focus. I've tried looking at the tab's content when the tabs SelectionChanged and setting the focus there but its not making a difference. Any ideas?

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

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

发布评论

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

评论(1

风向决定发型 2024-07-29 11:19:05

尝试监听 View.Loaded 事件,然后在处理程序中调用 View.focus()。 在初始化和加载元素之前,Wpf 不会接受焦点请求。 由于 SelectionChanged 事件是在视图加载之前引发的,因此焦点请求将被忽略。 每次元素隐藏后显示时都会调用loaded 事件。

有关焦点的更多信息,请参阅此博客文章:

http://www.julmar.com/blog/mark/PermaLink,guid,6e4769e5-a0b3-47b2-a142-6dfefd0c028e.aspx

Try listening for the View.Loaded event, then call View.focus() in the handler. Wpf will not accept focus requests before an element is initialized and loaded. Since the SelectionChanged event is raised before the view is loaded, the focus request will just be ignored. The loaded event is called each time the element is shown after being hidden.

See this blog post for more information on focus:

http://www.julmar.com/blog/mark/PermaLink,guid,6e4769e5-a0b3-47b2-a142-6dfefd0c028e.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文