- Mastering Windows Presentation Foundation
- Sheridan Yuen
- 299字
- 2021-06-24 16:49:04
Debugging data bound values
So far, we have seen that we can utilize a number of sources of information to help with tracking down the causes of our problems. However, what about actual debugging? In other GUI languages, we can add breakpoints at various locations in our code and watch our values changing as we step through our code. While we can also do this with WPF applications, it is not always so obvious where to put our breakpoints to ensure that program execution will hit them.
If you remember from the previous chapter, the CommandManager.RequerySuggested event is raised when CommandManager detects a change in the UI that could reflect on whether a command could execute or not. Well, it turns out that two of the conditions that the CommandManager looks out for is when the application window is either activated or deactivated and we can take advantage of this to help us when debugging. Note that the application window is deactivated when the user moves focus from it and is reactivated when the user returns focus to it.
Therefore, while running the application side by side with Visual Studio, we can put a breakpoint in any method that is being used as a canExecute handler for our ActionCommand class, thereby removing focus from the application. Now, when we click back on the WPF application, the focus will be returned to it.
This will cause the CommandManager.RequerySuggested event to be raised and as a result, the canExecute handler will be called and our breakpoint will be hit. This basically means that we are able to get the program execution into our View Models to debug parameter values any and every time that we need to. Let's see what else we can do to help fix our data binding errors.
- SQL Server 從入門到項(xiàng)目實(shí)踐(超值版)
- ASP.NET Core:Cloud-ready,Enterprise Web Application Development
- 零基礎(chǔ)搭建量化投資系統(tǒng):以Python為工具
- Visual FoxPro程序設(shè)計(jì)教程
- PLC編程與調(diào)試技術(shù)(松下系列)
- MATLAB 2020從入門到精通
- Advanced UFT 12 for Test Engineers Cookbook
- 大學(xué)計(jì)算機(jī)基礎(chǔ)
- Exploring SE for Android
- 3ds Max 2018從入門到精通
- 你好!Python
- 零基礎(chǔ)C語言學(xué)習(xí)筆記
- Mastering PostgreSQL 11(Second Edition)
- Scratch超人漫游記:創(chuàng)意程序設(shè)計(jì):STEAM創(chuàng)新教育指南
- Visual Basic程序設(shè)計(jì)