在 MVVM 中的 TextBox.GotFocus() 事件上显示日历
我有一个带有 TextBox 的应用程序。获得焦点后,我需要将日历显示为弹出窗口。
我的问题是如何通过视图模型显示订阅 GotFocus 事件并显示日历?
I have an application which is having TextBox. Upon getting the focus, I need to show the Calendar as Popup.
My question is how to show subscribe the GotFocus event and show the calendar through view model?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为像这样的特定于视图的任务编写代码隐藏是相当可以接受的,但是如果您坚持拥有干净的代码隐藏文件,请执行以下操作,
您将需要 MvvmLight.Extras.WPF4.dll 和 System.Windows.Interactivity。 dll,第二个DLL主要来自blend,谷歌第一个,无论如何你都可以在MVVMLight包上找到它们。
按如下方式引用它们:
在视图模型上查看文本框
,您应该有一个绑定到日历可见性属性的属性,在命令调用的方法中将其更改为可见。
It is fairly acceptable to write code-behind for view-specific tasks like this one, however if you insist to have clean code-behind files , do the following
you will need MvvmLight.Extras.WPF4.dll and System.Windows.Interactivity.dll, the second DLL comes mainly with blend , google the first and at any case you can find them both on the MVVMLight package.
reference them as follows:
see your textBox
on your view model you should have a property that is bound to your Calendar Visibility property , change it to Visible inside the method invoked by the command.
您实际上不需要为此转到 ViewModel - 它可以在 XAML 中非常简单地完成。在附加的绑定上使用 BooleanToVisibilityConverter到 TextBox 的 IsFocused 属性。
You really don't need to go to the ViewModel for this - it can be done very simply in XAML. Use a BooleanToVisibilityConverter on a binding that is attached to the TextBox's IsFocused property.