WPF 中 UserControl作为另一个Process宿主到Window里, ErrorTemplate的默认红框没有出现
2013-07-10 15:41
585 查看
最近做WPF项目遇到一个问题, 我有2个process, 一个Process里只有Usercontrol, 另一个Process获取前一个Process中Usercontrol并host到当前的window里。 结果Usercontrol里的ErrorTemplate默认的红框没有出现, 但是ValidationRule已经触发。
原因找见: Window类默认的Style包含AdornerDecorator元素, 而UserControl没有。 主要是因为UserControl经常应用在Window里或者其他上下文已经有了AdornerLayer。
解决办法: 在UserControl的逻辑树的根下添加AdornerDecorator, 如:<UserControl> <AdornerDecorator>
<Grid Background="Yellow">
...
</Grid>
</AdornerDecorator>
</UserControl>
还需要把子控件的Margin设置下, 腾出空间显示ErrorTemplate。
There is no AdornerLayer in which the error template can be drawn.
Window's default style includes an AdornerDecorator, but UserControl's does not. That's because UserControls are frequently used inside a Window or some other context that already supplies an AdornerLayer.
In your case there is no surrounding AdornerLayer, so you need to add one explicitly. In PASimulationView.xaml:
<AdornerDecorator>
<Grid Background="Yellow">
...
</Grid>
</AdornerDecorator>
You might also want to add a Margin to the TextBox, or do something else to move it away from the top and left edges of the UserControl, so that the top and left edges of the error template are visible.
https://connect.microsoft.com/VisualStudio/feedback/details/725602/wpf-validationrule-has-been-trigged-but-the-textboxs-default-errortemplate-did-not-show-red-border
相关文章推荐
- WPF 中 UserControl作为另一个Process宿主到Window里, ErrorTemplate的默认红框没有出现
- WPF 中 UserControl作为另一个Process宿主到Window里, ErrorTemplate的默认红框没有出现
- Mongodb中经常出现的错误:child process failed, exited with error number
- 代码提交 svn 出现 CreateProcess error 206(文件名或扩展名太长)问题的解决方法
- ControlTemplate in WPF —— Window
- 配置spring+mybatis时出现Error creating bean with name 'sqlSessionTemplate‘
- 使用开源sweetalert出现Error:Execution failed for task ':app:processDebugManifest'.
- adb连接时出现如下错误CreateProcess failure, error 2 * could not start server *
- android studio编程时出现的错误:Error:Execution failed for task ':app:processDebugResources'.
- 另一个开发WPF/E用的Template,无需Web Application Project
- 当您尝试查看 Web 页作为宿主的 IIS 6.0 上时出现错误消息: 页面无法显示"
- ubuntu 下出现E: Sub-process /usr/bin/dpkg returned an error code
- tensorboard 出现Fatal error in launcher: Unable to create process using '"'
- 中文作为参数传入 window.showModalDialog出现乱码的解决办法
- ControlTemplate in WPF —— Window
- 很多人都在埋怨没有遇到好的团队,但好的团队不可能凭空出现,一流的团队不能仅靠团队成员努力,作为Leader,要有可行的规划,并坚定地执行、时势地调整(转)
- 模板函数(template function)出现编译链接错误(link error)之解析
- C++ 将一个 Template Class 作为另一个类的友员
- [WPF疑难]ErrorTemplate显示与隐藏问题
- 解决办法:CMake编译时出现“error in configuration process project files may be invalid”