wpf - How to access Behaviours Property attached to window from ViewModel
问题描述
I have a dependency bool property inside a behavior, which was set in Window to ask the confirmation message popup before closing window. But I don't need this popup when it is being closed from ViewModel. So how can I access the property in the behavior and how to set it as False.
<Window WindowState="Normal" WindowStyle="SingleBorderWindow" ResizeMode="NoResize"
behaviors:WndExitAftConfirmBehaviour.Enabled="True"/>
How can I access the Enabled property in ViewModel and how to set it as False?
解决方案
与其将其设置为常量,True
不如将其绑定到视图模型中的布尔属性并将该属性设置为False
窗口关闭时。
如果您不使用数据绑定,那么只需执行以下操作:
Application.Current.MainWindow.SetValue(WndExitAftConfirmBehaviour.EnabledProperty, false);
推荐阅读
- javascript - 未定义(评估'this.props.navigation.navigate')React Native
- javascript - 一系列数字的最小公倍数 - 适用于 Codepen.io 而不是 freecodecamp.org
- wordpress - 致命错误:第 463 行的 C:\xampp\htdocs\AKS_Shop\wp-includes\Requests\Transport\cURL.php 中的最大执行时间超过 30 秒
- java - Android 格式化包含国家代码的国际电话号码字符串
- java - 如何使用 jaxrs-jersey 将 SecurityContext 以外的上下文传递给 swagger-codegen 应用程序
- angular - 如何修复错误“ID4183:安全令牌未通过受众限制验证。” 由 Sharepoint 抛出
- reactjs - 如何将 className 作为道具传递?
- javascript - 如何检查 JavaScript 对象数组中是否存在特定对象?
- nativescript - 如何在 nativescript 6 中的后退按钮事件上导航到特定页面
- react-native - 在 React Native 中将凝视渲染为组件