What techniques are there for debugging issues with data binding in a Windows Metro style application? Are there techniques available like those for WPF and Silverlight applications, described at:
How can I debug WPF bindings?
Debugging Data Bindings in a WPF or Silverlight Application
How can I turn binding errors into runtime exceptions?
EDIT: I was originally asking about WinRT data binding debugging techniques so that I could troubleshoot the issue described at Metro: Why is binding from XAML to a property defined in code-behind not working?. I eventually found a solution to this issue, but experimenting with the working solution, I did not see any message in the Visual Studio 11 output window when I purposely misspelled the property name so that it would not be found. It also does not appear that PresentationTraceSources is available to WinRT apps.
Another possible solution:
sealed partial class App : Application
{
public App()
{
this.InitializeComponent();
this.Suspending += OnSuspending;
DebugSettings.BindingFailed += OnDebugSettingsOnBindingFailed;
}
private void OnDebugSettingsOnBindingFailed(object sender, BindingFailedEventArgs args)
{
new MessageDialog(args.Message).ShowAsync();
}
...
}
Original source: http://www.tozon.info/blog/post/2012/07/23/Debugging-WinRTXAML-bindings.aspx
If you look at the output window in VS you will see data binding trace messages on errors. You get this automatically for C++ applications and for managed applications you have to turn on unmanaged debugging to see them. This is an area we are looking to improve on, but for now you have the ability to turn them on and see the trace outputs.
In VS11 beta, the templated projects offer a way to help debug binding errors.
I wrote it up here http://www.kelvinhammered.com/?p=150
I always use immediate window to track binding issues.
Here's what msdn says about it :
In some settings configurations, first-chance exception notifications
are displayed in the Immediate window.
To toggle first-chance exception notifications in the Immediate window
On the View menu, click Other Windows, and click Output.
Right-click on the text area of the Output window, and select or
deselect Exception Messages.
(in fact default setting was ok for me in vs2010)
hope this can help.
Related
I have no clue how long this feature/option has been around but my mouse happened to pause over this button within the WPF designer early and now I'm curious what it's purpose is.
Hovering over the button, Visual Studio pops up a tooltip that says Enable project code. When I click on it, the designer seems to reload the xaml contents but I can't tell what's changed.
What does this feature do?
2020 EDIT
It's been years since I've had to work in XAML, but I've received a new project where I need to work in XAML. This feature/button seems to have disappeared. Where has it migrated?
What does this feature do?
It enables or prevents the designer from running your code in the background.
Disabling project code can lead to a loss of design time data and enabling it can lead to unhandled exceptions in the XAML designer.
These exceptions are usually caused by code that attempts to access properties or methods which work differently when your application is running in the designer compared to when it runs as a built executable.
Debugging or Disabling Project Code in XAML Designer: https://msdn.microsoft.com/en-us/library/mt622752.aspx?f=255&MSPPError=-2147217396
I am creating a WPF Office add in, and I would like to handle all exceptions in one place. To do this I use the following code in the constructor of my MainWindowViewModel:
Dispatcher.CurrentDispatcher.UnhandledExceptionFilter += new
DispatcherUnhandledExceptionFilterEventHandler(HandleAllException);
In my test environment I host the WPF app from a console application project, and exceptions are handled as expected. When I host the WPF app from within word however, nothing happens when exceptions are thrown. There is no notification at all that there has even been an exception, other than in the output window in visual studio. Does anyone have any suggestions as to what I might be doing wrong?
I have solved the problem by changing the way in which I launch my WPF app. I believe the problem was related to this.
I've been working on a SL5 app for a few days. I've mostly been using a hard coded dummy data collection when styling my app's view. Everything has been working fine, but now I want to connect it to a dynamic data collection generated by my view model (using the data service technique where you have design time & real data depending on the IsInDesignTool property.
After I cleared out the control of the hard coded data and bound it to a collection in my view model. When I run it in debug mode, I see an unhandled exception being thrown in App.xaml.cs. The exception args don't say exactly what the problem is (it is simply saying "Value does not fall within the expected range" but when I look at the sender I find the following coming from the MainWindow (my app only has a single view): "Out-of-browser specific settings do not affect in-browser applications."
Further, when I try to view the MainWindow in the designer in VS, it doesn't render and instead shows an error (the rendered exception in the designer doesn't have any of my namespaces in it, just things about controls & UIElements).
I'm at a bit of a loss how to troubleshoot this. I didn't set anything for out-of-browser when building the app and since it worked with dummy data collections, why would it suddenly have this issue (seems like if I was using an out-of-browser property it would have shown up before I bound the data to the view).
Tips/pointers?
(sorry for my bad english)
I am not sure on what is happening but I saw the error "Out-of-browser specific..." when I tried to access some specific property only available to OOB while running on browser. The solution was to test if running oob before using the property:
if (Application.Current.IsRunningOutOfBrowser)
{
Application.Current.MainWindow.WindowState = WindowState.Maximized;
}
The other problem possibly is unrelated - and sometimes can be really hard to debug - one thing that helped me is to open another instance of VS and attach it to the one where you are seeing the problem. With this setup, go to your problematic View and change to "design view" - keep an eye on the Output window of the attached VS to see if some meaningful exception is shown.
I had a similar issue.
I did put a Textbox inside kind of Listbox (radPanelBar) and added
HorizontalScrollBarVisibility="Auto" to the Textbox. It seems that the textbox had problems when to show the scrollbar and when not. Adding
ScrollViewer.HorizontalScrollBarVisibility="Disabled" to the Listbox did solve it ( so, no OOB issue at all ).
I'm not entirely sure what the error was, but it wasn't at all realted to OOB. I'm using a data service approach (in design time I programatically build real data, not the Expression Blend sample data, but when not in a design tool, it uses the REST services). I started disabling a lot of things in my dynamic data and slowly added them back. Somewhere along the way my dummy data generation was fouling things up, but SL thought it was an OOB issue.
I have developed a simple DB-editing app using Xceed's excellent DataGrid for WPF (UX Edition version 3.7), which is now ready for deployment... except that when I run it on a machine other than the development one where it was built, I am getting the runtime exception for invalid licensing.
I have included my license key in the App.xaml.cs exactly as specified in the Xceed docs, like so:
public partial class App : System.Windows.Application
{
protected override void OnStartup(StartupEventArgs e)
{
Xceed.Wpf.DataGrid.Licenser.LicenseKey = "DGF37-xxxxx-xxxxx-xxxx";
base.OnStartup(e);
}
}
The correct version of the DataGrid DLLs are being included in the setup and the application's program directory, and there are no other versions on the target machine.
Debugging doesn't show me anything useful other than the LicenseException that is thrown when the code tries to use the DataGrid, with the message that reads "Xceed.Wpf.DataGrid.Licenser.LicenseKey property must be set to a valid license key in the code of your application before using this product..."
Any idea what's going wrong here?
Oh, poop... figured it out, and it was a stupid mistake. My OnStartup event was misplaced, outside of the app's namespace.
Not wanting to enter into the debate of wiring up event handlers in code or in XAML, sufice it to say, that I seem to recall there was a kind of "tab to create" feature in the XAML editor for silverlight projects. Clearly it's been a while since I have been codeing XAML, but I was sure it was a simple process of adding an event handler in the code behind file for a control on the XAML page.
Can somebody tell me if I'm dreaming?
I know for a fact you can use that feature when creating silverlight 2 projects.
Reapplying Visual Stduio 2008 SP1 corrected the issue -- go figure.