Skip to main content

Debugging databinding

WPF and Silverlight are great thanks to the rich databinding support. Important to notice is that late bound data binding is used bindings in XAML files. This feature allows a DataContext to be set at run-time and the objects within that DataContext to resolve their property bindings then. This late binding enables cool features like DataTemplates, composable applications and run-time loading of loose XAML.

A side effect of late bound binding resolution that databinding will fail silently if a value can not be found.  So troubleshooting why a specific field is not loaded in a control can be painfull. Therefore some tips to get some useful debugging information.

View the Debug Output Window

If you have the DataContext set, any data bindings within that DataContext that can't be resolved will be listed in the Debug Output Window at run-time.

WPF Trace Settings, Data Binding

The default value of the WPF Trace Settings, Data Binding is "Error." To get more data binding information change the level to "Warning". If the value is set to "Error" you won't see any of the PresentationTraceSources.TraceLevel warning messages.

To change the WPF Trace Settings, Data Binding value to "Warning," navigate to Tools, Options, Debugging, Output Window, WPF Trace Settings, Data Binding and set the value to Warning.

PresentationTraceSources.TraceLevel

Introduced to WPF in .NET 3.5 SP1, the PresentationTraceSources.TraceLevel attached property allows developers to dial up the amount of information outputted in the Debugger Output Window for a binding.

The below XAML snippet shows how to apply the PresentationTraceSources.TraceLevel attached property to a binding. 

   1:  <Window 
   2:      xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase"
   3:      xmlns:local="clr-namespace:DebugDataBindings"
   4:      x:Class="DebugDataBindings.MainWindow"
   5:      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   6:      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   7:      Title="MainWindow" Height="350" Width="525">
   8:      <Grid x:Name="layoutRoot">
   9:          <Grid.Resources>
  10:              <local:DebugConverter x:Key="debugConverter" /> 
  11:          </Grid.Resources>
  12:          <TextBox 
  13:              Text="{Binding Path=Customer.FirstName, diag:PresentationTraceSources.TraceLevel=High}"   
  14:              Height="23" HorizontalAlignment="Left" Margin="90,18,0,0" VerticalAlignment="Top" Width="120"/>
  15:      </Grid>
  16:  </Window>

Still not enough information? Have a look at the following blog posts:


Popular posts from this blog

Azure DevOps/ GitHub emoji

I’m really bad at remembering emoji’s. So here is cheat sheet with all emoji’s that can be used in tools that support the github emoji markdown markup: All credits go to rcaviers who created this list.

Kubernetes–Limit your environmental impact

Reducing the carbon footprint and CO2 emission of our (cloud) workloads, is a responsibility of all of us. If you are running a Kubernetes cluster, have a look at Kube-Green . kube-green is a simple Kubernetes operator that automatically shuts down (some of) your pods when you don't need them. A single pod produces about 11 Kg CO2eq per year( here the calculation). Reason enough to give it a try! Installing kube-green in your cluster The easiest way to install the operator in your cluster is through kubectl. We first need to install a cert-manager: kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.14.5/cert-manager.yaml Remark: Wait a minute before you continue as it can take some time before the cert-manager is up & running inside your cluster. Now we can install the kube-green operator: kubectl apply -f https://github.com/kube-green/kube-green/releases/latest/download/kube-green.yaml Now in the namespace where we want t...

Podman– Command execution failed with exit code 125

After updating WSL on one of the developer machines, Podman failed to work. When we took a look through Podman Desktop, we noticed that Podman had stopped running and returned the following error message: Error: Command execution failed with exit code 125 Here are the steps we tried to fix the issue: We started by running podman info to get some extra details on what could be wrong: >podman info OS: windows/amd64 provider: wsl version: 5.3.1 Cannot connect to Podman. Please verify your connection to the Linux system using `podman system connection list`, or try `podman machine init` and `podman machine start` to manage a new Linux VM Error: unable to connect to Podman socket: failed to connect: dial tcp 127.0.0.1:2655: connectex: No connection could be made because the target machine actively refused it. That makes sense as the podman VM was not running. Let’s check the VM: >podman machine list NAME         ...